2014-09-15 2 views
0

iOS 7에서 작동하는 코드가 있습니다. 모든 푸시 알림을 수신합니다.Parse.com을 사용하여 iOS 8에서 푸시 알림이 작동하지 않습니다.

Parse.com을 사용하여 새로운 iOS 8 푸시 알림을 구현할 때 제대로 작동하지 않습니다. 잘못하고 난`아무것도

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
    // Register for push notifications 
    [Parse setApplicationId:@"XXXX" clientKey:@"XXX"]; // REMOVED IDS FOR SECURITY REAS 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { 

     UIMutableUserNotificationAction *viewAction = [[UIMutableUserNotificationAction alloc] init]; 
     viewAction.identifier = @"medphone-view"; 
     viewAction.title = @"Ver"; 
     viewAction.activationMode = UIUserNotificationActivationModeForeground; 
     viewAction.destructive = NO; 

     UIMutableUserNotificationAction *dismissAction = [[UIMutableUserNotificationAction alloc] init]; 
     dismissAction.identifier = @"medphone-dismiss"; 
     dismissAction.title = @"Excluir"; 
     dismissAction.activationMode = UIUserNotificationActivationModeBackground; 
     dismissAction.destructive = YES; 

     UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init]; 
     category.identifier = @"medphone"; 
     [category setActions:[NSArray arrayWithObjects:viewAction, dismissAction, nil] forContext:UIUserNotificationActionContextDefault]; 

     NSSet *categories = [NSSet setWithObjects:category, nil]; 

     UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 
     UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; 
     [application registerUserNotificationSettings:mySettings]; 
     [application registerForRemoteNotifications]; 

    } else { 
     [application registerForRemoteNotificationTypes: 
     UIRemoteNotificationTypeBadge | 
     UIRemoteNotificationTypeAlert | 
     UIRemoteNotificationTypeSound]; 
    } 

    if (launchOptions) { //launchOptions is not nil 
     NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]; 
     NSLog(@"Push info %@", userInfo); 
     NSDictionary *apsInfo = [userInfo objectForKey:@"aps"]; 

     if (apsInfo) { //apsInfo is not nil 
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
      [prefs setValue:userInfo forKey:@"PUSHDATA"]; 
      [prefs setBool:YES forKey:@"PUSH"]; 
      [prefs synchronize]; 
      NSLog(@"entrou no UIApplicationLaunchOptionsRemoteNotificationKey %@", apsInfo); 
     } 
    } 

    return YES; 
} 

And these other methods: 

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    [currentInstallation setDeviceTokenFromData:deviceToken]; 
    currentInstallation.channels = @[@"global"]; 
    [currentInstallation saveInBackground]; 
} 

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:userInfo]; 
    NSLog(@"entrou no didReceiveRemoteNotification %@", userInfo); 
} 

#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 { 
    NSLog(@"entrou no UIApplicationLaunchOptionsRemoteNotificationKey %@", userInfo); 

    //handle the actions 
    if ([identifier isEqualToString:@"medphone-view"]) { 
     NSLog(@"ver"); 
    } else if ([identifier isEqualToString:@"medphone-dismiss"]) { 
     NSLog(@"dismmis"); 
    } 
    completionHandler(); 
} 



#endif 

있습니까 : 여기

코드인가? 페이로드는 정확하며 iOS 7에서 작동합니다. 카테고리가 설정됩니다.

제게 알려주세요.

+0

당신은 Parse.com에 앱 인증서를 업로드 했습니까? – Dehli

+0

당신이 말할 수 없다면 무슨 문제가 있습니까? 기기에 알림이 표시되지 않습니까? https://parse.com/docs/push_guide#options/iOS도 참조하십시오.이 문서는 범주 지원을 설명하기 위해 방금 업데이트되었습니다. –

+0

동일한 문제가 발생합니다. 설치를 확인하면 deviceToken이 설정되지 않습니다. – NoelHunter

답변

3

아이폰 OS 8의 코드가 변경되었습니다 :

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
{ [[UIApplication sharedApplication] registerUserNotificationSettings: 
    [UIUserNotificationSettings settingsForTypes: 
        (UIUserNotificationTypeSound | 
        UIUserNotificationTypeAlert | 
        UIUserNotificationTypeBadge) categories:nil]]; 

    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
} 
else 
{ 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
    (UIUserNotificationTypeBadge | 
     UIUserNotificationTypeSound | 
     UIUserNotificationTypeAlert)]; 
} 
관련 문제