【发布时间】:2019-05-10 10:12:38
【问题描述】:
我的应用是使用 Unity3d (2018) 和 c# 开发的。然后为 iOS 构建应用程序。现在,我想使用自定义方案来启动我的 iOS 应用并提供一些额外信息:
some-custom-scheme://some-parameter=some-value
我在Unity forum 中读到,最好的方法是在 Unity 中创建一个插件,并按照论坛帖子中的描述连接到 iOS 启动管道,如下所示:
-(BOOL)application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
NSArray *keyArray = [launchOptions allKeys];
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) {
NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
NSString *urlString = [url absoluteString];
[[NSUserDefaults standardUserDefaults] setObject:urlString forKey:@"url"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
在应用程序中,我只需像这样检查 PlayerPrefs:
var url = PlayerPrefs.GetString("url");
但是 url 值是空的。遍历键并在应用程序中提醒它们会产生两个结果:UIApplicationLaunchOptionsKey 和 UIApplicationLaunchOptionsSourceApplicationKey。根据the Apple documentation 两者都无关紧要,其中指出数据应该在 UIApplicationLaunchOptionsAnnotationKey 键中。
我还阅读了this SO question 告诉发布者使用openURL method。
我觉得我很接近但还没有。我做错了什么,如何解决?哪种方法更好?我使用 didFinishLaunchingWithOptions 或 openURL 方法的方法?
非常感谢任何帮助!
【问题讨论】:
标签: c# objective-c xcode unity3d