Xcode6 Swift添加远程推送通知并从PHP发送

时间:2015-02-06 23:30:08

标签: swift push-notification xcode6

我想通过PHP脚本向所有应用用户发送推送通知。关于Google遗憾的是,没有关于Swift推送通知的教程。 Parse.com我不想用。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:3)

现在好了! (:

为APN创建证书: raywenderlich.com

Swift Code:

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脚本和中提琴(: