How to do implement notification in iOS with Firebase
Issue #64
Note: This applies to Firebase 4.0.4
Preparing push notification certificate
Go to Member Center -> Certificates
-> Production
Certificate
You can now use 1 certificate for both sandbox and production environment
Auth Key
- If you like to use Auth Key, read Provider Authentication Tokens
Configure push notification
- Go to Firebase Console ->
Settings
->Project Settings
->Cloud Messaging
->iOS app configuration
- If you use certificate, use just 1
Apple Push Notification service SSL
for both fields - If you use Authenticate Key, fill in
APNS auth key
- If you use certificate, use just 1
Adding pod
In your Podfile
, declare
1 | pod 'Firebase/Core' |
Disabling app delegate swizzling
- Read Method swizzling in Firebase Cloud Messaging
- You should say NO to swizzling. Do this in your
Info.plist
1 | <key>FirebaseAppDelegateProxyEnabled</key> |
Read more on Messaging.messaging().apnsToken
This property is used to set the APNS Token received by the application delegate.
FIRMessaging uses method swizzling to ensure the APNS token is set automatically. However, if you have disabled swizzling by settingFirebaseAppDelegateProxyEnabled
toNO
in your app’s Info.plist, you should manually set the APNS token in your application delegate’s -application:didRegisterForRemoteNotificationsWithDeviceToken: method.
If you would like to set the type of the APNS token, rather than relying on automatic detection, see: -setAPNSToken:type:.
Configuring Firebase
You can and should configure Firebase in code
1 | import Firebase |
Handling device token
1 | import Firebase |
Getting FCM token
Retrieving FCM token
Read Access the registration token
By default, the FCM SDK generates a registration token for the client app instance on initial startup of your app. Similar to the APNs device token, this token allows you to target notification messages to this particular instance of the app.
1 | Messaging.messaging().fcmToken |
Observing for FCM token change
1 | Messaging.messaging().delegate = self |