The app has the push entitlement set, I am actually getting a token in the didRegisterForRemoteNotificationsWithDeviceToken delegate in objc in the same project (if I temporarily disable the Expo inits). Is there something I need to call to register it? It looks like it reads the apns from NSUserDefaults, but I didn’t see where registerForRemoteNotifications was called and then captured and stored that.
That is correct that the device token is read from NSUserDefaults for iOS. You’ll need to request remote notification permissions first Permissions.askAsync(Permissions.REMOTE_NOTIFICATIONS) and then call Notifications.getDevicePushTokenAsync()
Here’s a snippet of what worked for me:
// push-notifications.js
import {
Permissions,
Notifications
} from 'expo';
export async function registerForPushNotificationsAsync () {
const status = await Permissions.askAsync(Permissions.REMOTE_NOTIFICATIONS)
.then(({ status }) => status);
if (status === 'granted') {
const [expoToken, deviceToken] = await Promise.all([
Notifications.getExponentPushTokenAsync(),
Notifications.getDevicePushTokenAsync()
]);
return {
expoToken,
deviceToken,
};
}
const error = new Error('Permission denied');
error.status = status;
throw error;
}
And then elsewhere:
import { registerForPushNotificationsAsync } from '@something/push-notifications';
// ...
const { expoToken, deviceToken } = await registerForPushNotificationsAsync();
const { data: platformToken } = deviceToken;
// Do stuff with your deviceToken
// Also, handle your errors :)
@mglagola Thanks for the response. I am still getting the rejection but I jumped into the objc code some more to debug. In EXRemoteNotificationManager.m , registerForRemoteNotifications …
#ifdef EX_DETACHED
// DDLogWarn(@"Expo Remote Notification services won't work in an ExpoKit app because Expo can not manage your APNS certificates.");
#else
// don't register, because the detached app may not be built with APNS entitlements,
// and in that case this method would actually be bad to call. (not just a no-op.)
[RCTSharedApplication() registerForRemoteNotifications];
#endif
[RCTSharedApplication() registerForRemoteNotifications] (as well as didFail) is never going to be called. I commented out the #def however the didRegisterForRemoteNotificationsWithDeviceToken delegate is never called in ExpoKit.m, which is where the token is set in NSUserDefaults that the js function you wrote is called. Whats interesting is that if I drop didRegisterForRemoteNotificationsWithDeviceToken delegate in the AppDelegate.m in its indeed called, and when commenting that out again, the delegate in ExpoKit.m is not called. I think I am where ExpoKit.m is set as the delegate for didRegisterForRemoteNotificationsWithDeviceToken.