推远程通知

问题描述:

我需要在我的应用程序创建接收远程信息的代码,并将其推送到用户在应用程序上的背景,我在网上,我需要使用didReceiveRemoteNotification上的appDelegate,使用远程推送商品通知读取。我读了一些有关我需要的密钥和证书,我不知道如何使用didReceiveRemoteNotification推远程通知

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

+0

[How to在斯威夫特设置推送通知(http://*.com/questions/24899257/how-to-setup-push-notifications-in-swift) –

我用这个链接,我发现它最有用的

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) 
} 
+0

您好阿斯德鲁瓦尔,以感谢帮助,但我不明白,怎么应用接收json,在你发布的链接中,应用程序收到了json {“aps”:{“alert”:“你好,来自AppCoda!”,“badge”:1,“sound”:“default”}},但谁发送这个json?我可以使用PHP创建一个Web服务来发送json数据吗?但是,我把这个链接叫做什么? didReceiveRemoteNotification如何获取这些数据?如何安排? –

+0

我个人使用[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

+0

感谢您的帮助。 –