2016-01-13 4 views
0

Я реализую push-уведомление для ios. Но токен устройства получает для ipad, ios v 8.3, но когда я устанавливаю приложение в iphone 6s plus v9.0, тогда токен объявления не регистрируется .I создаю весь сертификат в соответствии с this reference, но я получаю уведомление в ipad, но не получаю iphone. Так что это problem.I не может найти out.please помочь мнеУстройство token не зарегистрировано для ios 9

if(IS_OS_8_OR_LATER) { 
    //Right, that is the point 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge 
                         |UIRemoteNotificationTypeSound 
                         |UIRemoteNotificationTypeAlert) categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
} 
else{ 
    //register to receive notifications 
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes]; 
} 


- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 
{ 
    [application registerForRemoteNotifications]; 
} 

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{ 
    NSString *token=[deviceToken description]; 
    token=[token stringByReplacingOccurrencesOfString:@">" withString:@""]; 
    token=[token stringByReplacingOccurrencesOfString:@"<" withString:@""]; 
    token=[token stringByReplacingOccurrencesOfString:@" " withString:@""]; 
    if (token != nil) { 
     [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DEVICE_TOKEN"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 
    } 
    NSLog(@"token-->%@",token); 
} 

-(void)registerDeviceToken 
{ 
    NSUserDefaults* errDefaults = [NSUserDefaults standardUserDefaults]; 
    NSString *regerr = @"no valid 'aps-environment' entitlement string found for application"; 
    if ([[errDefaults objectForKey:@"ErrDesc"] isEqual: regerr] || [errDefaults objectForKey:@"DEVICE_TOKEN"] == nil) { 
     UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Device token not register." message:@"Please check in member center that you have valid provisioning profile for your app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 
    else{ 
     NSUserDefaults* statusvalue = [NSUserDefaults standardUserDefaults]; 
     NSString *status = [statusvalue objectForKey:@"status"]; 
     NSLog(@"Status->%@",status); 
     if ([status isEqualToString: @"SUCCESS"]) 
     { 
      NSLog(@"%@",@"No need to register!!!"); 
     } 
     else 
     { 
      NSString *urlString=[NSString stringWithFormat:@"%@?email=&regid=%@&app_type=utnews_v1&mobile=%@",webAPIURL,[[NSUserDefaults standardUserDefaults] objectForKey:@"DEVICE_TOKEN"],[[NSUserDefaults standardUserDefaults] objectForKey:@"mobile_no"]]; 

      NSURL *url=[NSURL URLWithString:urlString]; 
      NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url]; 
      NSLog(@"url-->%@",request.URL); 
      [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
       if(error) 
       { 
        [[[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; 
       } 
       else if (data.length>0) 
       { 
        NSString *responseString=[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding]; 
        NSLog(@"Response string-->%@",responseString); 
        NSMutableDictionary *parsedObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
        NSString *parsevalue = parsedObject[@"status"]; 

        NSLog(@"%@",parsevalue); 

        NSUserDefaults* statusvalue = [NSUserDefaults standardUserDefaults]; 

        // Store data in prefereances 
        [statusvalue setObject:parsevalue forKey:@"status"]; 

        // Save to disk 
        [statusvalue synchronize]; 
        // NSDictionary *jsonDict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; 
       } 
       else 
       { 
        // [[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No response from server.Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; 
       } 
      }]; 
     } 
    } 
} 
+0

Не могли бы вы записать свой код? –

+0

Не используйте 'IS_OS_8_OR_LATER'. Существуют правильные способы проверки наличия API. – rmaddy

ответ

1

Может быть, вы должны добавить [[UIApplication sharedApplication] registerForRemoteNotifications]; в if(IS_OS_8_OR_LATER) заявлении. Надеюсь, что это поможет

0

Ниже приведена ваша проблема с версией iOS 6 и выше. registerForRemoteNotificationTypes Устарел от `iOS 8.0.

#ifdef __IPHONE_8_0 
if (IS_OS_EQUAL_GRETER_8) { 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    UIUserNotificationSettings *notificationSetting=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound| UIRemoteNotificationTypeBadge categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSetting]; 
}else{ 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound| UIRemoteNotificationTypeBadge)]; 
} 
#else 

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


#endif 
+0

Не используйте IS_OS_8_OR_LATER. Существуют правильные способы проверки наличия API. – rmaddy

Смежные вопросы