Skip to content

Instantly share code, notes, and snippets.

@ohtwo
Last active August 29, 2015 14:23
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 ohtwo/0456c21025d02943d7da to your computer and use it in GitHub Desktop.
Save ohtwo/0456c21025d02943d7da to your computer and use it in GitHub Desktop.
Setup push notifications in Swift
/**
* 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