Quickstart-ios: Unclear documentation

Created on 12 Dec 2016  路  16Comments  路  Source: firebase/quickstart-ios

This documentation page is unclear about what one should do in an app that disabled swizzling.

1) It shows the application:didReceiveRemoteNotification:fetchCompletionHandler:, but, doesn't it work with application:didReceiveRemoteNotification: too?
2) It says that "If you do not set these two delegates with AppDelegate, method swizzling for message handling is disabled", but, in order for the app to receive time zone based push notifications, "you must assign your delegate object to the FIRMessaging object", so does that mean that swizzling gets enabled back? Isn't swizzling status managed __ONLY__ by the FirebaseAppDelegateProxyEnabled Info.plist key?
3) If I set that delegate, what should I do in the delegate's implementation?

Most helpful comment

Couldn't this great explanation be added somewhere in the documentation?

All 16 comments

Hi @revolter sorry you had issues understanding how to use FCM when not swizzling.

  1. Yes it will work with the application:didReceiveRemoteNotification (for now) but it is the version without the fetchCompletionHandler is deprecated and so we only show the one with the fetchCompletionHandler.

  2. This is a note about FCM swizzling the handling of incoming messages. Maybe "method swizzling for message handling is disabled" should be "method swizzling will not work". Even if swizzling is enabled you still need to set your AppDelegate as your UNUserNotificationCenterDelegate and FIRMessagingDelegate for the automatic message handling to work.

Hi @kroikie, thanks for the response.

  1. I now saw that it's deprecated, but for some reason, Xcode isn't generating a warning for it. For now, I have both delegate methods implemented, which both calls [[FIRMessaging messaging] appDidReceiveMessage:userInfo];. From the documentation, it looks like Apple will only call the new one, so this shouldn't be a problem, right?

  2. Is setting the UNUserNotificationCenterDelegate mandatory for "Recipient time zone" based push messages?

  3. What about my 3rd question which I forgot to number? (sorry)

  1. Yes if the version with the completion handler is available is used otherwise the deprecated one is used.

  2. No, the UNUserNotificationCenterDelegate implementation is only necessary for receiving the callbacks.

  3. If you are asking what methods you should implement when adding UNUserNotificationCenterDelegate have a look at the sample the iOS 10 methods are marked. userNotificationCenter:willPresentNotification: and userNotificationCenter:didReceiveNotificationResponse: for data messages from FCM also implement applicationReceivedRemoteMessage from the FIRMessagingDelegate protocol.

  1. So should "you still need to set your AppDelegate as your UNUserNotificationCenterDelegate and FIRMessagingDelegate for the automatic message handling to work." be "you still need to set your AppDelegate as your UNUserNotificationCenterDelegate __or__ FIRMessagingDelegate for the automatic message handling to work." instead?

  2. Sorry again, hard day for me. I was asking about FIRMessagingDelegate's applicationReceivedRemoteMessage: method. Do I need to forward the call when having swizzling disabled in order for Firebase to correctly transform data notifications into local notifications?

  1. I will try to improve the wording to be clearer here. You would use the UNUserNotificationCenterDelegate methods if you want to get display notification callbacks (when your app is in the foreground or when a user taps on a notification and returns to your app etc). FIRMessagingDelegate is not needed for display notification handling.

  2. Data notifications are not transformed into local notifications by FCM. FIRMessagingDelegate's applicationReceivedRemoteMessage: is only for receiving data messages from FCM. If you want to generate a local notification at that point then you will have to implement that logic yourself.

  1. I don't want to generate a custom local notification. But, you said that the message should be 'should be "method swizzling will not work"'. So the documentation would be:

If you do not set these two delegates with AppDelegate, method swizzling will not work

That sounds to me as "Recipient time zone" based push notifications will not work if I don't set any delegate.

But why would I want to set a delegate if I don't want to do anything when the data notification is received? Also, as I said in the original issue, this documentation page says that "you must assign your delegate object to the FIRMessaging object".

This looks contradictory to me. Am I missing something?

If you are swizzling FCM will implement the required callbacks for you so no need for you to do it, however if you disable swizzling they you have to implement them and also call FIRMessaging's appDidReceiveMessage method so that FCM knows about the received message.

When you call appDidReceiveMessage then FCM can perform analytics and schedule messages.

I understand, but what about the FIRMessagingDelegate protocol method? Do I or do I not need to set the remoteMessageDelegate to receive time zone based notifications?

No, you only need to use the FIRMessagingDelegate if you would like to receive data messages (data payload and no notification payload) while your app is in the foreground.

Ok, I think I got it now, but it's still a bit twisted and hard to grasp.

You said that:

Yes it will work with the application:didReceiveRemoteNotification (for now) but it is the version without the fetchCompletionHandler is deprecated and so we only show the one with the fetchCompletionHandler.

but #157 presumably adds the deprecated one too, in order for messages to be received in iOS 10 too. Also, this section already shows both handlers, so why wouldn't the no swizzling one contain it?

The version with the completion handler is the recommended one so that is the one in the docs. A bug in iOS 10 called the deprecated version instead of the recommended one in some cases, so we added it to the sample in case someone is using the sample as a starter for a real app. When Apple fixes this issue we will remove the callback without the completion handler.

with swizzling enabled:

  • the APNs token is associated with the IID token automatically
  • Analytics logged automatically
  • Messages scheduled automatically

with swizzling disabled:

  • APNs token has to be associated with the IID token manually using setAPNSToken
  • Analytics logged and messages scheduled in callbacks (depending on iOS version) using appDidReceiveMessage

The callbacks you implement when swizzling is disabled depends on the iOS versions you are targeting.

Couldn't this great explanation be added somewhere in the documentation?

@kroikie your extra explanations have helped a great deal. The documentation however is still very confusing. Batch has a great step-by-step that might serve as good inspiration! Todd's guide on the blog is very human readable as well :)

The links mentioned Batch and Todds Guide above only talks about push notification and not pure data messaging. Also the FIRMessagingDelegate is now renamed to MessagingDelegate

@All, thanks for the feedback we are always working on our docs and samples, this thread will influence future updates.

Was this page helpful?
0 / 5 - 0 ratings