Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FirebaseAppDelegateProxyEnabled = no
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
- *print("launch didFinish" )
- FirebaseApp.configure()
- Messaging.messaging().delegate = self
- Messaging.messaging().shouldEstablishDirectChannel = true
- if #available(iOS 10.0, *) {
- // For iOS 10 display notification (sent via APNS)
- UNUserNotificationCenter.current().delegate = self
- let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
- UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { (isSuccess, error) in
- if let error = error {
- print("error: (error.localizedDescription)")
- }
- })
- } else {
- let settings: UIUserNotificationSettings =
- UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
- application.registerUserNotificationSettings(settings)
- }
- application.registeForRemoteNotifications()
- }
- func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
- InstanceID.instanceID().instanceID { (result, error) in
- if let error = error {
- print("Error fetching remote instance ID: (error)")
- } else if let result = result {
- Messaging.messaging().apnsToken = deviceToken
- print("Remote instance ID token: (result.token)")
- }
- }
- Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
- Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
- Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
- }
- func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
- // If you are receiving a notification message while your app is in the background,
- // this callback will not be fired till the user taps on the notification launching the application.
- // With swizzling disabled you must let Messaging know about the message, for Analytics
- Messaging.messaging().appDidReceiveMessage(userInfo)
- if let messageID = userInfo[gcmMessageIDKey] {
- print(userInfo)
- }
- }
- // Receive data message on iOS 10 devices while app is in the foreground.
- func applicationReceivedRemoteMessage(_ remoteMessage: MessagingRemoteMessage) {
- print("remoteMessage: (remoteMessage.appData)")
- guard let data: [String: Any] = remoteMessage.appData as? [String: Any] else {
- return
- }
- print("applicationReceivedRemoteMessage: (data)")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement