FIRMessaging


@interface FIRMessaging : NSObject

Firebase Messaging lets you reliably deliver messages at no cost.

To send or receive messages, the app must get a registration token from FIRInstanceID. This token authorizes an app server to send messages to an app instance.

In order to receive FIRMessaging messages, declare application:didReceiveRemoteNotification::fetchCompletionHandler:.

  • Delegate to handle FCM token refreshes, and remote data messages received via FCM direct channel.

    Declaration

    Objective-C

    @property (readwrite, nonatomic, nullable) id<FIRMessagingDelegate> delegate;
  • When set to YES, Firebase Messaging will automatically establish a socket-based, direct channel to the FCM server. Enable this only if you are sending upstream messages or receiving non-APNS, data-only messages in foregrounded apps. Default is NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL shouldEstablishDirectChannel;
  • Returns YES if the direct channel to the FCM server is active, and NO otherwise.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL isDirectChannelEstablished;
  • FIRMessaging

    Declaration

    Objective-C

    + (nonnull instancetype)messaging;

    Return Value

    An instance of FIRMessaging.

  • FIRMessagingExtensionHelper

    Use FIRMessagingExtensionHelper to populate rich UI contents for your notifications. e.g. If an image URL is set in your notification payload or on the console, call FIRMessagingExtensionHelper API to render it on your notification.

    Declaration

    Objective-C

    + (nonnull FIRMessagingExtensionHelper *)extensionHelper;

    Return Value

    An instance of FIRMessagingExtensionHelper that handles the extensions API.

  • Unavailable. Use +messaging instead.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • This property is used to set the APNS Token received by the application delegate.

    FIRMessaging uses method swizzling to ensure that the APNS token is set automatically. However, if you have disabled swizzling by setting FirebaseAppDelegateProxyEnabled to NO 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:.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSData *APNSToken;
  • Set APNS token for the application. This APNS token will be used to register with Firebase Messaging using FCMToken or tokenWithAuthorizedEntity:scope:options:handler.

    Declaration

    Objective-C

    - (void)setAPNSToken:(nonnull NSData *)apnsToken
                    type:(FIRMessagingAPNSTokenType)type;

    Parameters

    apnsToken

    The APNS token for the application.

    type

    The type of APNS token. Debug builds should use FIRMessagingAPNSTokenTypeSandbox. Alternatively, you can supply FIRMessagingAPNSTokenTypeUnknown to have the type automatically detected based on your provisioning profile.

  • Is Firebase Messaging token auto generation enabled? If this flag is disabled, Firebase Messaging will not generate token automatically for message delivery.

    If this flag is disabled, Firebase Messaging does not generate new tokens automatically for message delivery. If this flag is enabled, FCM generates a registration token on application start when there is no existing valid token. FCM also generates a new token when an existing token is deleted.

    This setting is persisted, and is applied on future invocations of your application. Once explicitly set, it overrides any settings in your Info.plist.

    By default, FCM automatic initialization is enabled. If you need to change the default (for example, because you want to prompt the user before getting token) set FirebaseMessagingAutoInitEnabled to false in your application’s Info.plist.

    Declaration

    Objective-C

    @property (getter=isAutoInitEnabled, assign, readwrite, nonatomic)
        BOOL autoInitEnabled;
  • The FCM token is used to identify this device so that FCM can send notifications to it. It is associated with your APNS token when the APNS token is supplied, so that sending messages to the FCM token will be delivered over APNS.

    The FCM token is sometimes refreshed automatically. In your FIRMessaging delegate, the delegate method messaging:didReceiveRegistrationToken: will be called once a token is available, or has been refreshed. Typically it should be called once per app start, but may be called more often, if token is invalidated or updated.

    Once you have an FCM token, you should send it to your application server, so it can use the FCM token to send notifications to your device.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *FCMToken;
  • Retrieves an FCM registration token for a particular Sender ID. This can be used to allow multiple senders to send notifications to the same device. By providing a different Sender ID than your default when fetching a token, you can create a new FCM token which you can give to a different sender. Both tokens will deliver notifications to your device, and you can revoke a token when you need to.

    This registration token is not cached by FIRMessaging. FIRMessaging should have an APNS token set before calling this to ensure that notifications can be delivered via APNS using this FCM token. You may re-retrieve the FCM token once you have the APNS token set, to associate it with the FCM token. The default FCM token is automatically associated with the APNS token, if the APNS token data is available.

    Declaration

    Objective-C

    - (void)retrieveFCMTokenForSenderID:(nonnull NSString *)senderID
                             completion:
                                 (nonnull FIRMessagingFCMTokenFetchCompletion)
                                     completion;

    Parameters

    senderID

    The Sender ID for a particular Firebase project.

    completion

    The completion handler to handle the token request.

  • Invalidates an FCM token for a particular Sender ID. That Sender ID cannot no longer send notificatio