I've integrated Twilio Programmable Chat, but I've had some issues with push notifications that I'm trying to sort out.
I'm looking at my code vs the example provided at https://www.twilio.com/docs/chat/ios/push-notifications-ios
The first thing I notice is that in the User Notification Setttings
section(beyond the extra t in the name of the section), the deprecated method [self.chatClient registerWithToken:nil];
from V1.0 is used. In the current documentation for V 2.2.2, we have - (void)registerWithNotificationToken:(nonnull NSData *)token completion:(nullable TCHCompletion)completion, which specifies nonnull NSData*
for the token parameter. So, we can't pass nil any longer. Is there anything we're now supposed to do for the if(notificationSettings.types == UIUserNotificationTypeNone)
case within - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
of our app delegate? (example provided in tutorial section mentioned above) Right now I just skip that step, and ensure that my updatedPushToken
property is set to nil.
I'm also wondering what the - (void)handleNotification:(nonnull NSDictionary *)notification completion:(nullable TCHCompletion)completion method on the TwilioChatClient
actually does. I see that the delegate has 5 different methods for notifications. Does this handleNotification
method simply call the appropriate delegate method? I didn't use this method myself, I just show an alert view with the message of the notification right now, so I'm wondering if there are additional benefits under the hood that I'm missing out on, or even potential bugs I'm introducing by not using the TwilioChatClient
handler.
The last and most important thing I'm wondering, that isn't touched in the tutorial, is how to handle registering for push notifications when a user has signed out and signed back in later. Is the deviceToken
returned from - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
meant to be stored somewhere with more permanence than a property of a singleton? Can I re-obtain it elsewhere, either via Twilio or maybe an iOS method I'm unaware of? It seems once I sign a user out, I'm unable to receive Notifications again when they sign in to a different or even the same user. I see that there is a deregisterWithNotificationToken:completion: method, but since it requires a nonnull token, I can only call it based on the tutorial if my app hasn't been closed. What's the recommended way to hang on to this token? NSUserDefaults? Somewhere on my server's database?
Edit: I have another question, actually. If I uncheck the read status box, then re-check it, on a chat instance configuration, will that reset everyone's unread channel count? I had the setting of the consumption horizon / read status done improperly, and I also have a lot of channels hidden from users even though they are in them... so, with the badge count enabled, users are probably seeing very high numbers any time they get a single message, and won't be able to completely reduce this number back down to 0, even if they open every channel they can currently view. I'd prefer to just reset this number. As mentioned in my comments, I dislike that the only options I have are no notification badge, or a notification badge explicitly set to the number of channels that have unread messages... I would most prefer an option to just increment the badge, and, barring that, the notification that does not include a specific number. I want people to see that they have chats, as it is very important, but I don't want these high numbers being displayed, and those unread messages don't stay relevant permanently. Only new unread messages are relevant.
registerWithNotificationToken:completion:
using nil will show a warning when done explicitly, simply returns a result in the block that returns false forisSuccessful
and contains the error messageNo notification token provided.
So, nothing will crash, but it appears to be a completely unnecessary call in the tutorial. The proper, up to date method is called within the function called when a token exists. If you use that example code with the up to date SDK, though, you'll get a compiler error since the method does not exist. – Jake T.[UIApplication sharedApplication] registerForRemoteNotifications]
after push notifications have been approved will immediately call- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
again. Apple specifically recommends not caching this token, and instead calling that method to obtain it again as needed. Unless that's wrong, only the middle question is left. Is there a benefit to implementinghandleNotification
if I don't intend to use the delegate methods? – Jake T.