2014-12-04 47 views
9

Projemde push bildirimi için Parse SDK kullanıyorum. parse.com üzerinde verildiği gibi ben didFinishLaunchingWithOptions: kodu eklemişRegisterUserNotificationSettings ios içinde çalışmıyor 6.1

UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | 
               UIUserNotificationTypeBadge | 
               UIUserNotificationTypeSound); 
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes 
                     categories:nil]; 


[application registerUserNotificationSettings:settings]; 
[application registerForRemoteNotifications]; 

onun çalışma ince, cihaz veya simülatör sürümü iOS 8, ama onun iOS 6.1 çalışmıyor ve ileti ise görünen

[UIApplication registerUserNotificationSettings:]: unrecognized selector sent to instance 0x208406c0

Herhangi biri bana nasıl çözebileceğimi söyleyebilir mi?

cevap

29

kullanım didFinishLaunchingWithOptions yönteminde bu kod ios 6 iş ve 7

[application registerForRemoteNotificationTypes: 
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; 

sen her durumda 6,7,8 ardından didFinishLaunchingWithOptions içine bu kodu kullanılan IOS içinde çalışmak istiyorsanız olduğunu

iOS8 için
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
    { 
     // iOS 8 Notifications 
     [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

     [application registerForRemoteNotifications]; 
    } 
    else 
    { 
     // iOS < 8 Notifications 
     [application registerForRemoteNotificationTypes: 
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; 
    } 
+0

güzel ancak herhangi bir olumsuz Çalışır? – okysabeni

+2

@Yko, Bunu pek çok projede kullandım ancak herhangi bir sorunla karşılaşmadım. –

1

:

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
} else { 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 
}