DKCode DKCode - 1 month ago 21
Swift Question

Xcode6 Swift add Remote Push Notifications and send from PHP

I want to send Push Notifications via a PHP script to all app users. About Google Unfortunately there are no tutorials for Push Notifications with Swift. Parse.com I do not want to use. Can anyone help me please?

Answer

OK now it works ! (:

Create Certificate for 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)

}

find the deviceToken in the Xcode Console

PHP Script

use the PHP Script from here raywenderlich.com (scroll down)

run the PHP Script and viola (:

Comments