Skip to content

Instantly share code, notes, and snippets.

@volkanbicer
Forked from benaneesh/Push.swift
Created October 5, 2017 20:26
Show Gist options
  • Save volkanbicer/1a1cf5da076186e85f9087fffca0a71d to your computer and use it in GitHub Desktop.
Save volkanbicer/1a1cf5da076186e85f9087fffca0a71d to your computer and use it in GitHub Desktop.
Push notification in swift (iOS)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// notification
if let options = launchOptions {
let notificationPayload: NSDictionary = options[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary
// do somehting with the notifications
}
// Register for Push Notitications, if running iOS 8
if application.respondsToSelector("registerUserNotificationSettings:") {
let types:UIUserNotificationType = (.Alert | .Badge | .Sound)
let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
// Register for Push Notifications before iOS 8
application.registerForRemoteNotificationTypes(.Alert | .Badge | .Sound)
}
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
println("didRegisterForRemoteNotificationsWithDeviceToken")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println("failed to register for remote notifications: (error)")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
println("didReceiveRemoteNotification")
if application.applicationState == .Active {
} else {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment