我已经在我们的应用程序中实现了 Handoff,当应用程序在前台或后台运行时,它对于 web 到应用程序的切换工作正常,反之亦然。
但是,如果应用程序没有运行,那么如果用户从 web 启动应用程序到应用程序切换,在 launchOptions 字典中,我得到UIApplicationLaunchOptionsUserActivityDictionaryKey
,但缺少对活动的引用。
看截图:
如您所见,我只获得了NSUserActivity
. 这是 iOS 9 中的错误吗?
有没有办法通过使用 id 来获取对活动的引用?
编辑,这里是代码,虽然我不认为这是相关的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions && [[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
__block NSUserActivity *activity;
NSDictionary *userActivityDictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey];
if (userActivityDictionary) {
[userActivityDictionary enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[NSUserActivity class]]) {
activity = obj;
}
}];
}
//app was started by URL (deep linking), check parameters
if (activity) {
NSURL *url = activity.webpageURL;
//resume from URL
}
}
return YES;
}