2011-08-09 95 views
1

我想在推送通知上單擊查看按鈕時啓動我的應用程序,但如果應用程序不在後臺,我的應用程序就會終止。ios推送通知終止應用程序

這是來自控制檯的錯誤信息。

Aug 9 10:35:41 unknown listingApp[4527] <Error>: -[__NSCFDictionary absoluteString]: unrecognized selector sent to instance 0x1a8b50 
Aug 9 10:35:41 unknown listingApp[4527] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary absoluteString]: unrecognized selector sent to instance 0x1a8b50' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x36df764f __exceptionPreprocess + 114 
    1 libobjc.A.dylib      0x34050c5d objc_exception_throw + 24 
    2 CoreFoundation      0x36dfb1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102 
    3 CoreFoundation      0x36dfa649 ___forwarding___ + 508 
    4 CoreFoundation      0x36d71180 _CF_forwarding_prep_0 + 48 
    5 listingApp       0x00002d09 -[AppDelegate application:didFinishLaunchingWithOptions:] + 220 
    6 UIKit        0x35c12821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772 
    7 UIKit        0x35c0cb65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272 
    8 UIKit        0x35be17d7 -[UIApplication handleEvent:withNewEvent:] + 1114 
    9 UIKit        0x35be1215 -[UIApplication sendEvent:] + 44 
    10 UIKit        0x35be0c53 _UIApplicationHandleEvent + 5090 
    11 GraphicsServices     0x3651be77 PurpleEventCallback + 666 
    12 CoreFoundation      0x36dcea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26 
    13 CoreFoundation      0x36dd083f __CFRunLoopDoSource1 + 166 
    14 CoreFoundation      0x36dd160d __CFRunLoopRun + 520 
    15 CoreFoundation      0x36d61ec3 CFRunLoopRunSpecific + 230 
    16 CoreFoundation      0x36d61dcb CFRunLoopRunInMode + 58 
    17 UIKit        0x35c0bd49 -[UIApplication _run] + 372 
    18 UIKit        0x35c09807 UIApplicationMain + 670 
    19 listingApp       0x00002b93 main + 78 
    20 listingApp       0x00002b0c start + 52 
) 
Aug 9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: terminate called after throwing an instance of ' 
Aug 9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: NSException 
Aug 9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: ' 
Aug 9 10:35:41 unknown ReportCrash[4528] <Notice>: Formulating crash report for process listingApp[4527] 
Aug 9 10:35:41 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:co.isale.isale[0xc768]) Job appears to have crashed: Abort trap: 6 

,這是我didFinishlaunchWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

NSLog(@"didFinishLaunchingWithOptions"); 
viewController.webView = webView; 
[viewController.view addSubview:webView]; 


// read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist 
NSArray* supportedOrientations = [self parseInterfaceOrientations: 
              [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]]; 

// read from PhoneGap.plist in the app bundle 
NSDictionary *temp = [[self class] getBundlePlist:@"PhoneGap"]; 
settings = [[NSDictionary alloc] initWithDictionary:temp]; 

viewController = [ [ PhoneGapViewController alloc ] init ]; 

NSNumber *useLocation   = [settings objectForKey:@"UseLocation"]; 
NSString *topActivityIndicator = [settings objectForKey:@"TopActivityIndicator"]; 


// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait) 
[[UIApplication sharedApplication] setStatusBarOrientation:[[supportedOrientations objectAtIndex:0] intValue]]; 

// push notification 
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 
// end of push notification 

這個代碼是從所謂的AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 


NSArray *keyArray = [launchOptions allKeys]; 
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) 
{ 
    NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]]; 
    self.invokeString = [url absoluteString]; 
    NSLog(@"listingApp launchOptions = %@",url); 
} 

return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
} 

請幫助另一位代表文件的開頭? 許多感謝感謝:)

+0

你需要表現出一定的代碼。 – jtbandes

+0

對不起:)你可以看到這是我的第一篇文章,現在會發布代碼 – Min

回答

0

您似乎在字典上調用absoluteString,在那裏您可能打算在NSURL對象上執行此操作。

重新您最新的代碼示例:

你正在做的事情很奇怪,試圖找到在launchOptions字典中的第一個關鍵。這不是如何使用字典。您應該使用的按鍵(上市here啓動選項鍵)直接,就像這樣:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey] 

    if (url) 
    { 
     self.invokeString = [url absoluteString]; 
     NSLog(@"listingApp launchOptions = %@", url); 
    } 

    return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
} 
+0

謝謝@Pnutus我會在原貼中張貼另一個代碼 – Min

+0

謝謝@Pnutus,我會試試你的解決方案:) – Min

+0

@Min,它工作嗎? –

0

看起來你還沒有實現的方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

當收到通知時調用此方法。

+0

不,我不這麼認爲 - 注意實際的錯誤是關於調用'absoluteString'的。這可能是一個內存管理錯誤。 – jtbandes

+0

你說得對,我沒有注意到它。 –

+0

感謝ibeitia的快速響應,不幸的是,didReceiveRemoteNotificaion只會在應用程序處於後臺時才能工作。 – Min