Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AppDelegate
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
- // Override point for customization after application launch.
- Parse.setApplicationId("zMeZbr9sfYSeRqqLONcjbDcL6lpXWXWROSoVDEKX",
- clientKey: "Whotpga5dCDY96bpfYiHHl8MNEQGJcLhGagfFWkA")
- // Register for Push Notitications
- if application.applicationState != UIApplicationState.Background {
- // Track an app open here if we launch with a push, unless
- // "content_available" was used to trigger a background push (introduced in iOS 7).
- // In that case, we skip tracking here to avoid double counting the app-open.
- let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
- let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
- var pushPayload = false
- if let options = launchOptions {
- pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
- }
- if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
- PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
- }
- }
- let types: UIUserNotificationType = [.Alert, .Badge, .Sound]
- let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
- application.registerUserNotificationSettings(settings)
- application.registerForRemoteNotifications()
- 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 {
- print("Push notifications are not supported in the iOS Simulator.")
- } else {
- print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
- }
- }
- func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
- PFPush.handlePush(userInfo)
- if application.applicationState == UIApplicationState.Inactive {
- PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement