简体   繁体   中英

starting to work with iOS push notifications

i started following this tutorial i found via google.

http://code.tutsplus.com/tutorials/setting-up-push-notifications-on-ios--cms-21925

However i got stuck on basically the first step where it said that the methods are deprecated, i changed them to the ones suggested by Xcode the original code was

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

i changed it to

  [application registerForRemoteNotification:(UIRemoteNotificationType | UIRemoteNotificationType | UIRemoteNotificationTypeSound)];

but i keep getting the error message saying " expected expression "

i'm still at the first step here, this tutorial i'm following is for ios 6 now i'm working on iOS 8 and i can't find any full tutorials on how to implement the push notifications to my application. can anyone point me in the right direction ?

You are using the API wrongly.

First of all the Push Notification API has changed after iOS 8.0.

My answer will assume that you want to still supporting iOS 7.x and later

// Checks if the application responds to the API introduced in iOS 8.
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    // iOS 8 Support
    // Note that you pass a object of type UIUserNotificationSettings as parameter instead of the enums only.
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];
} else {
    // Old API so use the same code from the tutorial
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM