我需要在我的應用程序創建接收遠程信息的代碼,並將其推送到用戶在應用程序上的背景,我在網上,我需要使用didReceiveRemoteNotification上的appDelegate,使用遠程推送商品通知讀取。我讀了一些有關我需要的密鑰和證書,我不知道如何使用didReceiveRemoteNotification推遠程通知
我需要了解推動遠程通知,以及如何使用。我想要一個教程或示例如何使用swift 2.3創建它。
我需要在我的應用程序創建接收遠程信息的代碼,並將其推送到用戶在應用程序上的背景,我在網上,我需要使用didReceiveRemoteNotification上的appDelegate,使用遠程推送商品通知讀取。我讀了一些有關我需要的密鑰和證書,我不知道如何使用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)
}
您好阿斯德魯瓦爾,以感謝幫助,但我不明白,怎麼應用接收json,在你發佈的鏈接中,應用程序收到了json {「aps」:{「alert」:「你好,來自AppCoda!」,「badge」:1,「sound」:「default」}},但誰發送這個json?我可以使用PHP創建一個Web服務來發送json數據嗎?但是,我把這個鏈接叫做什麼? didReceiveRemoteNotification如何獲取這些數據?如何安排? –
我個人使用[Amazon SNS](http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html),但我也看到有人使用[Parse](https:/ /parse.com/tutorials/push-notifications)。您可以爲APN創建一個Web服務器。此鏈接可能會幫助您http://samvermette.com/145。我不確定蘋果服務器和您的設備之間的一切如何發生 – Asdrubal
感謝您的幫助。 –
[How to在斯威夫特設置推送通知(http://stackoverflow.com/questions/24899257/how-to-setup-push-notifications-in-swift) –