5

由于事件的顺序会根据这两种情况中的哪一种情况而略有不同,因此我希望能够分辨出其中的区别。有什么建议么?

4

3 回答 3

10

您不应该使用handleOpenURL它,因为它已被弃用。而是使用application:openURL:sourceApplication:annotation:(自 iOS 4.2 起可用)。

Apple 的文档在这里为您提供了有关以下问题的答案application:openURL:sourceApplication:annotation

如果您的应用必须启动才能打开 URL,则应用首先调用 application:willFinishLaunchingWithOptions: 和 application:didFinishLaunchingWithOptions: 方法,然后是此方法。这些方法的返回值可用于防止调用此方法。(如果应用程序已经在运行,则只调用此方法。)

于 2013-08-20T12:40:24.743 回答
2

你在 AppDelegate 中试过这个方法吗?

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    NSLog(@"Launched with URL: %@", url.absoluteString);

    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_OPENED_FROM_LINK object:[userDict objectAtIndex:0]];

    return YES;
}
于 2013-08-20T12:36:34.963 回答
1

在我的情况下,如果应用程序在后台运行时启动应用程序,我必须再次创建导航流,但如果应用程序是第一次启动,则不需要这样做。我的实现是:

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.appIsLaunchedFromZeroToOpenURL = false;
    //some other code 
    NSURL *applicationOpenURL = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
    if (applicationOpenURL) {
        self.appIsLaunchedFromZeroToOpenURL = true;
    }
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if (self.appIsLaunchedFromZeroToOpenURL == false) {
        //app should reload the navigation then navigate to url if the app is not launched for the first time
       [self createNavigationFromZero];
    }
    [self openURL:url];//navigate to the url
    self.appIsLaunchedFromZeroToOpenURL = false;
}
于 2015-11-30T12:25:51.040 回答