2010-06-02 28 views
4

我已成功將自己的網址方案添加到我的應用程序中。該應用程序正確啓動使用該計劃。handleOpenURL在iPhone操作系統中未使用自定義網址架構調用

現在我想處理傳入的數據,但委託沒有被調用。這是一個普遍的應用程序,我還增加了以下功能都AppDelegates:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 
    if (!url) { return NO; } 

    NSString *URLString = [url absoluteString]; 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:NSLocalizedString(@"test message", nil) 
          message:URLString 
          delegate:self 
          cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
    [alert show];  
    [alert release]; 
    return YES; 
} 

我與喜歡的模式測試:MYAPP://appalarm.com ......並認爲那些是appalarm.com在URLString

它有什麼問題?

感謝您的回覆!

回答

5

如果您的應用程序委託已實施'applicationDidFinishLaunchingWithOptions:',那麼'handleOpenURL:'方法將永遠不會被調用。查看通過其他方法傳入的選項,以確定您的應用程序的啓動方式以及您應執行的行爲。

+2

的感謝!該網址也包含在UIApplicationLaunchOptionsURLKey – favo 2010-06-03 10:20:07

+0

的launchOptions中錯誤!如果返回YES,handleOpenURL將在applicationDidFinishLaunchingWithOptions後不久調用。請參閱Apple的「適用於iOS的應用程序編程指南」中「應用程序間通信」一章中的「處理URL請求」一節。 – AmitP 2015-08-25 15:14:40

7

我試圖澄清在another post。阿什利克拉克的答案只是部分正確。在OS 4.0下,handleOpenURL被調用(至少對於文件URL),並且必須實現它才能處理應用程序在後臺時打開的url調用。因此,在這兩種方法中打開文件可能會打開它兩次(如果applicationDidFinishLaunchingWithOptions返回YES,它應該)。見another post

1

試試你的代碼到下面的功能

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 
    if (!url) { return NO; } 

    NSString *URLString = [url absoluteString]; 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:NSLocalizedString(@"test message", nil) 
          message:URLString 
          delegate:self 
          cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
    [alert show];  
    [alert release]; 
    return YES; 
} 
相關問題