我在我们的应用程序中实现了Handoff,当应用程序在前台或后台运行时,它适用于Web到应用程序切换,反之亦然.
但是,如果应用程序未运行,那么如果用户从Web启动应用程序到应用程序切换,则在launchOptions字典中,我将获得UIApplicationLaunchOptionsUserActivityDictionaryKey,但缺少对该活动的引用.
看截图:
正如您所看到的,我只获得了NSUserActivity的ID.
这是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; }
解决方法
好,
我已经向Apple提交了一份有关此问题的TSI,似乎这不是一个错误,而是设计.
您可以在应用程序中恢复您的活动:continueUserActivity:restorationHandler委托,在我的情况下没有被调用.
好吧,我的错误是你需要在应用程序中返回YES:didFinishLaunchingWithOptions:方法,否则如果你返回NO,应用程序:continueUserActivity:recoverHandler不会被调用.
我们在我们的应用程序中实现了FB,所以我们返回[[FBSDKApplicationDelegate sharedInstance]应用程序:application didFinishLaunchingWithOptions:launchOptions],返回NO.
我在应用程序中更改了我们的代码:didFinishLaunchingWithOptions:function to this
if (launchOptions && [[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) { return YES; } else { return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; }
这样应用程序:continueUserActivity:recoverHandler委托被成功调用,活动可以成功恢复.