我的应用程序的通知,我无法弄清楚,为什么应用程序在推送通知对话框后崩溃 . 如果我在崩溃后再次运行应用程序它将正常工作,并且令牌将在我的数据库中注册

真的很感谢你对这个问题的帮助 .

提前致谢

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self registerPushNotification];
    //[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    //[self loadQuestionsAnswersFromPlist];
    [Tapjoy requestTapjoyConnect:@"xxx" secretKey:@"xx" options:@{ TJC_OPTION_ENABLE_LOGGING : @(YES) } ];
    [NSThread sleepForTimeInterval:2.0f];

    [self.window addSubview:_tabBarController.view];
    [self.window makeKeyAndVisible];

    return YES;
}


-(void) registerPushNotification {
    NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
    NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
    float versionVal = [prefix floatValue];


    if (versionVal >= 8)
    {


        //for iOS8
        UIUserNotificationSettings *settings =
        [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
         UIUserNotificationTypeBadge |
         UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];


    }
    else

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

}

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
    //handle the actions
    if ([identifier isEqualToString:@"declineAction"]){
    }
    else if ([identifier isEqualToString:@"answerAction"]){
    }
}
#endif

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)devviceToken
{
    self.deviceToken = [[[devviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];
    SessionData* sData = [SessionData sharedManager];
    sData.hasReceivedToken = TRUE;
    sData.token = self.deviceToken;
    if (sData.isRegistered) {
        id<MyInfoViewDelegate> myInfoVC = [[_tabBarController viewControllers] objectAtIndex:0];
        [myInfoVC saveDeviceToken:self.deviceToken];

    }
}


- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);

}

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

    if (application.applicationState == UIApplicationStateInactive ||
        application.applicationState == UIApplicationStateBackground) {
        application.applicationIconBadgeNumber = 0;
    }

    NSDictionary* keys = [userInfo objectForKey:@"aps"];
    NSString* alert = [keys objectForKey:@"alert"];
    int code = [[keys objectForKey:@"code"]intValue];
    if (code == 1) {
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"New Question" message:alert delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alertView show];
    }
}

日志

2014-10-07 07:26:13.603 Health Screener [145:60b]启动 Profiles 请求 - 2.1.17 with options:63 2014-10-07 07:26:14.486 Health Screener [145:60b] [TJLog级别:4] Tapjoy请求:https://connect.tapjoy.com/connect? 2014-10-07 07:26:16.821 Health Screener [145:60b]应用程序窗口预计在应用程序启动结束时会有一个根视图控制器2014-10-07 07:26:17.930 Health Screener [145:60b] [TJLog级别:4]连接成功与类型:0 2014-10-07 07:26:18.197 Health Screener [145:60b] {“success”:true,“output”:{“success”:true,“userid” :1284,“udid”:2014-10-07 07:26:19.988 Health Screener [145:60b] [TJLog级别:4]事件代理准备就绪2014-10-07 07:26:21.178 Health Screener [145:60b ] - [UINavigationController saveDeviceToken:]:无法识别的选择器发送到实例0x17565670 2014-10-07 07:26:21.181 Health Screener [145:60b] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UINavigationController saveDeviceToken: ]:无法识别的选择器发送到实例0x17565670'*第一次调用堆栈:(0x2d7eaf83 0x37f9bccf 0x2d7ee917 0x2d7ed203 0x2d73c768 0x343c7 0x30329867 0x3032a3d5 0x3119df2f 0x2d7b5a67 0x2d7b5a03 0x2d7b41d7 0x2d71eebf 0x2d71eca3 0x32624663 0 x3006b14d 0x337ed 0x384a8ab7)libc abi.dylib:以NSException类型的未捕获异常终止

// savedevicetoken

  • (void)saveDeviceToken:(NSString *)deviceToken {self.api.requestCode = 5; NSString * baseURL = [BASE_URL stringByAppendingString:SAVE_DEVICE_TOKEN];

SessionData * sData = [SessionData sharedManager];
NSMutableString * parameters = [NSMutableString string]; [参数appendFormat:@“uid =%d”,sData.userId]; [参数
appendFormat:@ “&标记=%@”,deviceToken];的NSLog(@ “%@”,参数); [self.api httpPost:baseURL withRequest:parameters]; } - (void)didFinishRequest {NSError * e = nil;
NSDictionary * output = [NSJSONSerialization JSONObjectWithData:[self.api.message dataUsingEncoding:NSUTF8StringEncoding]选项:
NSJSONReadingMutableContainers错误:&e]; BOOL success = [[output objectForKey:@“success”] boolValue]; if(self.api.requestCode == 1){if(success){SessionData * sData = [SessionData sharedManager]; sData.userId = [[[output objectForKey:@“output”] objectForKey:@“userid”] intValue]; sData.isRegistered = YES; if(sData.hasReceivedToken){sData.callGetAnswers = YES; [self saveDeviceToken:sData.token]; } else {[self getQuestionsAndAnswers]; }} else {UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“错误”消息:@“您没有互联网连接,请在有互联网连接时再试一次 . ” delegate:nil cancelButtonTitle:@“OK”otherButtonTitles:nil,nil]; [警示显示]; } return; }