Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. FirebaseAppDelegateProxyEnabled = no
  2.  
  3. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  4. *print("launch didFinish" )
  5.  
  6. FirebaseApp.configure()
  7. Messaging.messaging().delegate = self
  8. Messaging.messaging().shouldEstablishDirectChannel = true
  9. if #available(iOS 10.0, *) {
  10. // For iOS 10 display notification (sent via APNS)
  11. UNUserNotificationCenter.current().delegate = self
  12. let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  13. UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { (isSuccess, error) in
  14. if let error = error {
  15. print("error: (error.localizedDescription)")
  16. }
  17. })
  18.  
  19. } else {
  20. let settings: UIUserNotificationSettings =
  21. UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  22. application.registerUserNotificationSettings(settings)
  23. }
  24. application.registeForRemoteNotifications()
  25. }
  26.  
  27.  
  28. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  29. InstanceID.instanceID().instanceID { (result, error) in
  30. if let error = error {
  31. print("Error fetching remote instance ID: (error)")
  32. } else if let result = result {
  33. Messaging.messaging().apnsToken = deviceToken
  34. print("Remote instance ID token: (result.token)")
  35.  
  36. }
  37. }
  38. Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
  39. Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
  40. Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
  41. }
  42.  
  43. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
  44. // If you are receiving a notification message while your app is in the background,
  45. // this callback will not be fired till the user taps on the notification launching the application.
  46.  
  47. // With swizzling disabled you must let Messaging know about the message, for Analytics
  48. Messaging.messaging().appDidReceiveMessage(userInfo)
  49.  
  50. if let messageID = userInfo[gcmMessageIDKey] {
  51. print(userInfo)
  52. }
  53. }
  54.  
  55. // Receive data message on iOS 10 devices while app is in the foreground.
  56. func applicationReceivedRemoteMessage(_ remoteMessage: MessagingRemoteMessage) {
  57. print("remoteMessage: (remoteMessage.appData)")
  58. guard let data: [String: Any] = remoteMessage.appData as? [String: Any] else {
  59. return
  60. }
  61.  
  62. print("applicationReceivedRemoteMessage: (data)")
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement