Updated 18 July 2017
Application most important feature is push notification but it’s tough to implement using APNS as compared to Firebase. These steps you have to follow using push notification in iOS.
and add these flags go to Build Settings – choose Other Linker Flags: – add the following flags -lstdc++ -ObjC -lz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) FIRApp.configure() NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil) return true } // get the device token func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { var tokenq = "" for i in 0..<deviceToken.count { tokenq = tokenq + String(format: "%02.2hhx", arguments: [deviceToken[i]]) } print(tokenq) FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.sandbox ) FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.prod ) } // get instance firebase token func tokenRefreshNotification(_ notification: Notification) { if let refreshedToken = FIRInstanceID.instanceID().token() { print("InstanceID token: \(refreshedToken)") } // Connect to FCM since connection may have failed when attempted before having a token. connectToFcm() } func connectToFcm() { FIRMessaging.messaging().connect { (error) in if error != nil { print("Unable to connect with FCM. \(error)") } else { print("Connected to FCM.") } } } // get you message func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { print("Message ID: \(userInfo["gcm.message_id"]!)") // Print full message. print(userInfo) } |
6. Then you can send messages from Firebase console you can notification from there.
7. If you want to send notification from postman or implement from server side follow this link https://mobikul.com/send-push-notification-via-firebase-ios-postman/
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.