开始使用iOS推送通知

开始使用iOS推送通知,ios,objective-c,push-notification,Ios,Objective C,Push Notification,我开始学习通过谷歌找到的教程 但是我基本上停留在第一步,它说这些方法不推荐使用,我将它们改为Xcode建议的方法 原来的代码是 [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 我把它改成了 [application registerForRe

我开始学习通过谷歌找到的教程

但是我基本上停留在第一步,它说这些方法不推荐使用,我将它们改为Xcode建议的方法 原来的代码是

   [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
我把它改成了

  [application registerForRemoteNotification:(UIRemoteNotificationType | UIRemoteNotificationType | UIRemoteNotificationTypeSound)];
但我一直收到错误消息说“expected expression”

我仍处于第一步,下面的教程是针对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)];
}

在这行代码下仍然给我不推荐的。。。[application RegisterForRemotionTificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];]谢谢,我会继续使用你给我的代码和我正在学习的教程,看看我是否能让它一起工作:)如果你的目标是iOS 8和更高版本,它会发出警告,那么你不需要担心if测试,只需要马上使用API。如果你使用的是7或更高版本,那么你需要进行If测试。啊,好的,我这么做是因为正如你所说,我的应用程序针对的是iOS 8+。。。它就像一个魔咒。。。谢谢