开始使用 iOS 推送通知

starting to work with iOS push notifications

我开始学习通过 google 找到的本教程。

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

但是我基本上停留在第一步,它说这些方法已被弃用,我将它们更改为 Xcode 建议的方法 原始代码是

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

我改成了

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

但我不断收到“预期表达式”的错误消息

我仍处于第一步,我正在学习的本教程适用于 ios 6 现在我正在研究 iOS 8,我找不到任何关于如何将推送通知实现到我的应用程序的完整教程。谁能指出我正确的方向?

您错误地使用了 API。

首先,推送通知 API 在 iOS 8.0 之后发生了变化。

我的回答将假定您仍想支持 iOS 7.x 及更高版本

// 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)];
}