didRegisterForRemoteNotificationsWithDeviceToken not Called

Reva Yoga Pradana
1 min readJun 16, 2021

In our iOS App, we often found a condition when user are not getting push token from APNS. When we researching this, it’s because of:

neither the application:didRegisterForRemoteNotificationsWithDeviceToken: method nor the application:didFailToRegisterForRemoteNotificationsWithError: method is called.

When we do some next research, we also found that

on some connections, especially Wi-Fi connection, the port of APNS (5223) may got blocked.

https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html#//apple_ref/doc/uid/TP40008194-CH6-SW3

Because of “impossible case to handle” like that, this case may got more attention into our development process. For example, we should exclude the “mandatory push token” into our vital flow, e.g: Login Flow, or educating the users to (maybe) “Switch the internet operator for a while” when getting this condition.

To decreasing the occuring of that condition, we can do some enhancement in our code, related to registering remote push notifications. After discussing with Apple and reading the Leanplum’s documentation, we found out that we can call registerForRemoteNotifications() whenever users are accept or denying the push notifications. Although we register the remote notifications, Apple will still exclude the push notifications into our users, when they rejecting the push notification, so it’s safe to still calling this function. The example code will be like this:

So, just it. Thank you guys for reading this!

--

--

Reva Yoga Pradana

Engineering Manager — Software Engineer — iOS — Infra @ OVO.id | ex Bukalapak.com