2015-09-15 57 views
1

我爲我的包含應用程序設置了Today Extension。從Today窗口調用openURL會打開應用程序,但不會調用應用程序:openURL:sourceApplication:註釋:

下面是代碼:

TodayViewController:

[self.extensionContext openURL:[NSURL URLWithString:[NSString stringWithFormat:@"idaxiang://action=%ld",(long)aCell.tag]] completionHandler:^(BOOL success) { 
NSLog(@"open url result:%d",success);}]; 

AppDelegate.m:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ 

    NSString* prefix = @"idaxiang://action="; 

    if ([ElephantUtils originString:[url absoluteString] withTargetString:prefix]) { 

    if ([[url absoluteString] rangeOfString:prefix].location != NSNotFound) { 
     NSString* action = [[url absoluteString] substringFromIndex:prefix.length]; 

     UINavigationController *navc = (UINavigationController *)application.keyWindow.rootViewController; 
     if (navc.viewControllers.count > 1) { 
      [navc popToRootViewControllerAnimated:NO]; 
     } 
     ElephantHomeViewController *homeVC = (ElephantHomeViewController *)navc.topViewController; 
     [homeVC PushToSpecificArticle:[action integerValue]];    
    } 
    return [[Diplomat sharedInstance] handleOpenURL:url]; 
} 

但奇怪的是,如果包含應用程序無法打開(不加載到內存),我點擊Today Extension中的單元格,應用程序將打開,但不能撥打application:openURL:sourceApplication:annotation:,因此它不會推送到目標視圖控制器。但現在,應用程序已打開(已加載到內存),我點擊Today Extension中的單元格,包含的應用程序將調用application:openURL:sourceApplication:annotation:併成功推送到目標視圖控制器。

這裏是我的info.plist:

<dict> 
     <key>CFBundleTypeRole</key> 
     <string>Editor</string> 
     <key>CFBundleURLName</key> 
     <string>com.smartisanelephant.www</string> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string>idaxiang</string> 
     </array> 
    </dict> 

請給我一些建議,我一直在努力這個問題了一些日子。非常感謝!

+0

'application:openURL:sourceApplication:annotation:'should should be called when you launch your app via a URL scheme。你確定它沒有被調用?也許你的URL解析代碼中有一個錯誤? –

回答

0

我沒有足夠的信譽發表評論,但

當您嘗試從擴展啓動它被調用這個方法?

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
+0

我從設備日誌中調試它,但它在應用程序啓動時沒有調用' - (BOOL)應用程序:(UIApplication *)應用程序handleOpenURL:(NSURL *)url'。 – KittenYang

相關問題