Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. //AppDelegate
  2. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  3. // Override point for customization after application launch.
  4. Parse.setApplicationId("zMeZbr9sfYSeRqqLONcjbDcL6lpXWXWROSoVDEKX",
  5. clientKey: "Whotpga5dCDY96bpfYiHHl8MNEQGJcLhGagfFWkA")
  6.  
  7. // Register for Push Notitications
  8. if application.applicationState != UIApplicationState.Background {
  9. // Track an app open here if we launch with a push, unless
  10. // "content_available" was used to trigger a background push (introduced in iOS 7).
  11. // In that case, we skip tracking here to avoid double counting the app-open.
  12.  
  13. let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
  14. let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
  15. var pushPayload = false
  16. if let options = launchOptions {
  17. pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
  18. }
  19. if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
  20. PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
  21. }
  22. }
  23.  
  24. let types: UIUserNotificationType = [.Alert, .Badge, .Sound]
  25. let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
  26. application.registerUserNotificationSettings(settings)
  27. application.registerForRemoteNotifications()
  28.  
  29.  
  30. return true
  31. }
  32.  
  33.  
  34. func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
  35. let installation = PFInstallation.currentInstallation()
  36. installation.setDeviceTokenFromData(deviceToken)
  37. installation.saveInBackground()
  38. }
  39.  
  40. func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
  41. if error.code == 3010 {
  42. print("Push notifications are not supported in the iOS Simulator.")
  43. } else {
  44. print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
  45. }
  46. }
  47.  
  48. func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
  49. PFPush.handlePush(userInfo)
  50. if application.applicationState == UIApplicationState.Inactive {
  51. PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement