gpt4 book ai didi

swift - 推送远程通知

转载 作者:行者123 更新时间:2023-11-30 13:14:28 25 4
gpt4 key购买 nike

我需要在我的应用程序中创建一个代码,用于接收远程信息并在应用程序处于后台时将其推送给用户,我在网上读到我需要在 appDelegate 上使用 didReceiveRemoteNotification 来使用远程推送通知。我读到一些内容,我需要 key 和证书,我不明白如何使用 didReceiveRemoteNotification

我需要了解推送远程通知以及如何使用。我想要一个教程或示例如何使用 swift 2.3 创建它。

最佳答案

我使用了这个链接,我发现它最有帮助

http://www.appcoda.com/push-notification-ios/

我用这个应用程序进行测试

https://itunes.apple.com/us/app/easy-apns-provider-push-notification/id989622350?mt=12

这是我的 AppDelegate 中的代码

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

registerForPushNotifications(application)

print(UIDevice.currentDevice().identifierForVendor!.UUIDString)

return true
}


func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var tokenString = ""

for i in 0..<deviceToken.length {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}

print("Device Token:", tokenString)
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print("Failed to register:", error)
}

关于swift - 推送远程通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38382293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com