Last active
August 29, 2015 14:23
-
-
Save ohtwo/0456c21025d02943d7da to your computer and use it in GitHub Desktop.
Setup push notifications in Swift
This file contains hidden or 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
/** | |
* How to setup push notifications in Swift | |
* http://stackoverflow.com/questions/24899257/how-to-setup-push-notifications-in-swift | |
*/ | |
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
// 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 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment