-
-
Save volkanbicer/1a1cf5da076186e85f9087fffca0a71d to your computer and use it in GitHub Desktop.
Push notification in swift (iOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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