2014-12-04 16 views
9

Tôi đang sử dụng SDK Parse để thông báo đẩy trong dự án của mình. Tôi đã thêm mã trong didFinishLaunchingWithOptions: như được đưa ra trên parse.comRegisterUserNotificationCài đặt không hoạt động trong ios 6.1

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


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

nó làm việc tốt, nếu thiết bị hoặc phiên bản mô phỏng là iOS 8, nhưng nó không làm việc trong iOS 6.1, và thông điệp xuất hiện

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

Bất kỳ ai có thể cho tôi biết cách tôi có thể giải quyết nó?

Trả lời

29

sử dụng mã này trong phương pháp didFinishLaunchingWithOptions nó là công việc trong ios 6 và 7

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

nếu bạn muốn làm việc trong ios 6,7,8 trong mọi trường hợp thì sử dụng mã này bên trong một didFinishLaunchingWithOptions

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

Làm đẹp nhưng bất cứ nhược điểm? – okysabeni

+2

@Yko, tôi đã sử dụng điều này trong nhiều dự án nhưng không gặp bất kỳ vấn đề gì. –

1

Đối iOS8:

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)]; 
} 
Các vấn đề liên quan