您的位置:首页 > 移动开发 > Unity3D

在unity中打开ios手机上的其他app

2016-07-12 17:32 513 查看
在unity中新建类Open,记得<span style="font-family: Arial, Helvetica, sans-serif;">引用 System.Runtime.InteropServices; </span><pre name="code" class="csharp">
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class Open : MonoBehaviour {

[DllImport("__Internal")]
private static extern void OpenA ();

[DllImport("__Internal")]
public static extern void OpenB ();

[DllImport("__Internal")]
public static extern void OpenC ();

[DllImport("__Internal")]
private static extern int getNum();

public void ClickButtonA(){
OpenA ();
}

public void ClickButtonB(){
OpenB ();
}

public void ClickButtonC(){
OpenC ();
}
}
在项目中Assets/<span style="font-family: Arial, Helvetica, sans-serif;">Plugins/iOS 下添加.mm文件</span>
////  OpenApp.m//////  Created by apple on 16/7/12.////
#import <Foundation/Foundation.h>extern "C"{void OpenA(){//打开自定义url的app,与object-c中url写法稍有不同(<span class="s1" style="font-family: Arial, Helvetica, sans-serif;">@"aaa11://%@"</span><span style="font-family: Arial, Helvetica, sans-serif;">)</span>
        NSURL *url = [NSURL URLWithString:@"aaa11://"];[[UIApplication sharedApplication] openURL:url];}void OpenB(){NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/wechat/id836500024?mt=12//"];[[UIApplication sharedApplication] openURL:url];}void OpenC(){//经ios9.2设备测试,这两种方式打开app前都要经过app store//        NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/ai-qi-yihd-wo-qu-shang-xue/id409563112?mt=8//"];//        [[UIApplication sharedApplication] openURL:url];NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/ai-qi-yihd-wo-qu-shang-xue/id409563112?mt=8//"];[[UIApplication sharedApplication] openURL:url];}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity ios 打开app