Xcode6 Swift 添加远程推送通知并从 PHP 发送
Xcode6 Swift add Remote Push Notifications and send from PHP
我想通过 PHP 脚本向所有应用程序用户发送推送通知。关于 Google 不幸的是,Swift 没有关于推送通知的教程。 Parse.com我不想用。谁能帮帮我?
好的,现在可以了! (:
为 APN 创建证书:
raywenderlich.com
Swift代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
var setting = UIUserNotificationSettings(forTypes: type, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(setting)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
println(deviceToken)
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println(error)
}
在 Xcode 控制台中找到 deviceToken
PHP 脚本
使用此处的 PHP 脚本 raywenderlich.com(向下滚动)
运行 PHP 脚本和中提琴 (:
我想通过 PHP 脚本向所有应用程序用户发送推送通知。关于 Google 不幸的是,Swift 没有关于推送通知的教程。 Parse.com我不想用。谁能帮帮我?
好的,现在可以了! (:
为 APN 创建证书: raywenderlich.com
Swift代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
var setting = UIUserNotificationSettings(forTypes: type, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(setting)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
println(deviceToken)
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println(error)
}
在 Xcode 控制台中找到 deviceToken
PHP 脚本
使用此处的 PHP 脚本 raywenderlich.com(向下滚动)
运行 PHP 脚本和中提琴 (: