在同意接收推送通知后,该应用程序崩溃了iPhone

时间:2014-09-30 15:09:14

标签: ios objective-c push-notification

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

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

提前致谢

 - (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]开始个人资料   请求使用 - 2.1.17与选项:63 2014-10-07 07:26:14.486健康   筛选[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健康   筛选[145:60B]   { “成功”:真正的 “输出”:{ “成功”:真实的, “用户ID”: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健康   筛选器[145:60b] *由于未捕获的异常而终止应用程序   'NSInvalidArgumentException',原因:' - [UINavigationController   saveDeviceToken:]:无法识别的选择器发送到实例0x17565670'   * 第一次抛出调用堆栈:(0x2d7eaf83 0x37f9bccf 0x2d7ee917 0x2d7ed203 0x2d73c768 0x343c7 0x30329867 0x3032a3d5 0x3119df2f   0x2d7b5a67 0x2d7b5a03 0x2d7b41d7 0x2d71eebf 0x2d71eca3 0x32624663   0x3006b14d 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];     [parameters appendFormat:@"uid=%d",sData.userId];   [parameters
     

appendFormat:@ “&安培;标记=%@”,deviceToken];的NSLog(@ “%@”,参数);         [self.api httpPost:baseURL withRequest:parameters]; }

     

- (void)didFinishRequest {

NSError *e = nil;
NSDictionary *output = [NSJSONSerialization JSONObjectWithData: [self.api.message dataUsingEncoding:NSUTF8StringEncoding] options:
     

NSJSONReadingMutableContainers错误:&amp; 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:@“Error”消息:@“你没有互联网连接,   当你有互联网连接时再试一次。“委托:没有   cancelButtonTitle:@“OK”otherButtonTitles:nil,nil];               [警示显示];           }           返回;       }

0 个答案:

没有答案
相关问题