Skip to content

Instantly share code, notes, and snippets.

@burhanaksendir
Created June 18, 2015 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burhanaksendir/02820df6d0f1c335d6f9 to your computer and use it in GitHub Desktop.
Save burhanaksendir/02820df6d0f1c335d6f9 to your computer and use it in GitHub Desktop.
AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Parse initialization
Parse.setApplicationId(“xxxxxxxxxxxxxxxx", clientKey: “xxxxxxxxxxxxx")
let types = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
application.registerUserNotificationSettings(settings)
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let installation = PFInstallation.currentInstallation()
installation.setDeviceTokenFromData(deviceToken)
installation.saveInBackground()
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error.code == 3010 {
println("Push notifications are not supported in the iOS Simulator.")
} else {
println("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
NSNotificationCenter.defaultCenter().postNotificationName("remoteNotificationReceived", object: nil, userInfo: userInfo)
}
func applicationDidBecomeActive(application: UIApplication) {
if application.applicationIconBadgeNumber != 0 {
application.applicationIconBadgeNumber = 0
let installation = PFInstallation.currentInstallation()
installation.saveInBackground()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment