如何在斯威夫特设置推送通知 [英] How to setup push notifications in Swift
问题描述
我想建立一个推送通知系统,我的应用程序。我有一台服务器和开发人员许可证来设置推送通知服务。
I am trying to setup a push notification system for my application. I have a server and a developer license to setup the push notification service.
我目前运行我的斯威夫特应用程序。我希望能够从我的服务器远程发送通知。我怎样才能做到这一点?
I am currently running my app in Swift. I would like to be able to send the notifications remotely from my server. How can I do this?
推荐答案
要注册通过苹果推送服务将收到推送通知,你得叫 registerForRemoteNotifications()
的方法的UIApplication
。
To register to receive push notifications via Apple Push Service you have to call a registerForRemoteNotifications()
method of UIApplication
.
如果注册成功,应用程序调用您的应用程序委托对象的应用程序:didRegisterForRemoteNotificationsWithDeviceToken:
方法并传递一个设备令牌。
If registration succeeds, the app calls your app delegate object’s application:didRegisterForRemoteNotificationsWithDeviceToken:
method and passes it a device token.
您应该传递此令牌一起使用来生成设备推送通知服务器。如果注册失败,应用程序调用的应用程序委托的应用程序:didFailToRegisterForRemoteNotificationsWithError:
方法,而不是
You should pass this token along to the server you use to generate push notifications for the device. If registration fails, the app calls its app delegate’s application:didFailToRegisterForRemoteNotificationsWithError:
method instead.
看一看到<一个href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html\">Local和推送通知编程指南。
这篇关于如何在斯威夫特设置推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!