2015-06-14 58 views
1

我開始遵循本教程,我通過谷歌發現。開始使用iOS推送通知

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上工作,我找不到任何完整的教程關於如何實現推送通知我的應用程序。任何人都可以將我指向正確的方向嗎?

回答

2

您錯誤地使用了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)]; 
} 
+0

仍然給我此行的代碼下棄用...... [應用registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound )]; } 謝謝,我將繼續與你給我的代碼一起工作,隨着我正在跟隨的教程,看看我是否可以讓它一起工作:) – jack

+0

它會給出警告,如果你的目標是iOS 8以上,那麼你不需要擔心if測試,只需馬上就可以使用API​​。如果您使用7或更高,則需要進行if測試。 –

+1

啊okey我做到了這一點,因爲你說我的應用程序是針對iOS 8 + ...而且它像一個魅力工作...謝謝 – jack