question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Permission request for notification in SDK 37 crashes on iOS device

See original GitHub issue

🐛 Bug Report

Environment

After upgrading to SDK 37, the prompt in my application which requests a user to allow permissions for notifications now crashes my app. It works fine on the iOS simulator but crashes on an actual iOS device.

Stack-trace from Testflight is:

Incident Identifier: 9AE1BC0D-51B4-451A-AA97-74E4F9FFC88B
Beta Identifier:     CEBF2709-4BD3-47F3-A161-FF57F868FC4A
Hardware Model:      iPhone10,3
Process:             ComTryhikearound [463]
Path:                /private/var/containers/Bundle/Application/076822FF-9A87-47E3-AA19-CCB976F16B19/ExpoKitApp.app/ComTryhikearound
Identifier:          com.tryhikearound
Version:             1 (0.0.9)
AppStoreTools:       11E146
AppVariant:          1:iPhone10,3:13
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.tryhikearound [544]


Date/Time:           2020-03-31 19:17:00.5491 -0700
Launch Time:         2020-03-31 19:16:56.2785 -0700
OS Version:          iPhone OS 13.3.1 (17D50)
Release Type:        User
Baseband Version:    5.30.01
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  2

Last Exception Backtrace:
0   CoreFoundation                	0x1afb16a48 __exceptionPreprocess + 220 (NSException.m:199)
1   libobjc.A.dylib               	0x1af83dfa4 objc_exception_throw + 56 (objc-exception.mm:565)
2   CoreFoundation                	0x1afb6c360 _CFThrowFormattedException + 112 (CFObject.m:1990)
3   CoreFoundation                	0x1afb42000 _CFPrefsValidateValueForKey + 240 (CFPrefsSource.m:688)
4   CoreFoundation                	0x1afb426c8 createDeepCopyOfValueForKey + 160 (CFPrefsSource.m:744)
5   CoreFoundation                	0x1afb423c0 -[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:] + 328 (CFPrefsSource.m:762)
6   CoreFoundation                	0x1afb4277c -[CFPrefsSource setValues:forKeys:count:copyValues:from:] + 36 (CFPrefsSource.m:793)
7   CoreFoundation                	0x1af9f2bd4 -[CFPrefsSource setValue:forKey:from:] + 64 (CFPrefsSource.m:799)
8   CoreFoundation                	0x1afb4a7e4 __76-[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:]_block_invoke + 64 (CFXPreferences.m:795)
9   CoreFoundation                	0x1afa7fab8 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurat... + 376 (CFPrefsSearchListSource.m:1719)
10  CoreFoundation                	0x1afa7f350 normalizeQuintuplet + 356 (CFPrefsSearchListSource.m:68)
11  CoreFoundation                	0x1af9ef570 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationUR... + 124 (CFPrefsSearchListSource.m:1591)
12  CoreFoundation                	0x1af9f2628 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 108 (CFXPreferences.m:791)
13  CoreFoundation                	0x1afb4d9f0 _CFPreferencesSetAppValueWithContainerAndConfiguration + 132 (CFXPreferences.m:1853)
14  Foundation                    	0x1afe0e670 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 64 (NSUserDefaults.m:226)
15  ComTryhikearound              	0x10434d56c -[EXPermissionsManager synchronizeWithPermissions:] + 96 (EXPermissionsManager.m:75)
16  ComTryhikearound              	0x10434d4dc -[EXPermissionsManager savePermission:ofType:forExperience:] + 340 (EXPermissionsManager.m:69)
17  ComTryhikearound              	0x1043582b0 __74-[EXScopedPermissions askForPermissionUsingRequesterClass:resolve:reject:]_block_invoke + 136 (EXScopedPermissions.m:73)
18  ComTryhikearound              	0x1042e0c24 __85-[EXPermissions askForGlobalPermissionUsingRequesterClass:withResolver:withRejecter:]_block_i... + 68 (EXPermissions.m:163)
19  ComTryhikearound              	0x1042e1dd0 -[EXRemoteNotificationPermissionRequester _maybeConsumeResolverWithCurrentPermissions] + 96 (EXRemoteNotificationPermissionRequester.m:130)
20  ComTryhikearound              	0x1042e1d08 __84-[EXRemoteNotificationPermissionRequester _handleDidRegisterForRemoteNotifications:]_block_in... + 36 (EXRemoteNotificationPermissionRequester.m:116)
21  libdispatch.dylib             	0x1af7e2610 _dispatch_call_block_and_release + 24 (init.c:1408)
22  libdispatch.dylib             	0x1af7e3184 _dispatch_client_callout + 16 (object.m:495)
23  libdispatch.dylib             	0x1af7c0710 _dispatch_lane_serial_drain$VARIANT$armv81 + 564 (inline_internal.h:2484)
24  libdispatch.dylib             	0x1af7c1128 _dispatch_lane_invoke$VARIANT$armv81 + 400 (queue.c:3863)
25  libdispatch.dylib             	0x1af7ca43c _dispatch_workloop_worker_thread + 576 (queue.c:6445)
26  libsystem_pthread.dylib       	0x1af832b88 _pthread_wqthread + 276 (pthread.c:2351)
27  libsystem_pthread.dylib       	0x1af835760 start_wqthread + 8

Steps to Reproduce Code snippet that’s causing the crash is:

import { Notifications } from 'expo';
import * as Permissions from 'expo-permissions';
import { db, auth } from '../lib/Fire';

export async function registerForPushNotifications() {
    const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

    if (status !== 'granted') {
        return;
    }

    const user = auth.currentUser;
    const notificationToken = await Notifications.getExpoPushTokenAsync();

    db.collection('users')
        .doc(user.uid)
        .set({ notificationToken }, { merge: true });
}

Expected Behavior

I would expect that code snippet to prompt a user to allow notifications on iOS.

Actual Behavior

The app crashes. For some reason this crash isn’t registering with Sentry either.

Reproducible Demo

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sjchmielacommented, Apr 1, 2020

Thank you for providing the extra stack-trace, we now know what’s the problem. We will fix it and update the builders shortly. 🙌

1reaction
sjchmielacommented, Apr 1, 2020

I honestly have no idea how to reasonably explain this bug. May I ask you:

  • could you try to askAsync for Permissions.USER_FACING_NOTIFICATIONS? Does this crash too (what is the stacktrace)? This will let us know if the EXUserFacingNotificationsRequester that the EXRemoteNotificationsRequester uses is registered correctly.
  • does calling askAsync(NOTIFICATIONS) after a successful call to askAsync(USER_FACING_NOTIFICATIONS) crashes too? This should answer the question of whether there is some problem in modules registration
  • did this happen more than one time? This should help us inspect whether the crash happens only when the first-time dialog is opened or not?
  • could you try uninstalling the app from the device, restarting the device and reinstalling the app again? This should help us get rid of any side effects of having some data persisted from previous installations.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash affecting iOS 15/15.1 on iPad | Apple Developer Forums
After update 15.1 on my iPhone , nothing works. Several crashes when in use on different apps, rebooting my device and battery life...
Read more >
My iPhone App crashes after getting push notification in some ...
My app crashes on launch after receiving push notification. I tested on 5 devices and 2 of them crashed due to the issue(both...
Read more >
Troubleshooting | Home Assistant Companion Docs
If you are running Home Assistant 0.110 and the app crashes after clicking "continue" ... iOS In the iOS Settings application, navigate to...
Read more >
Using the Notifications API - MDN Web Docs
In our todo list demo, we include an "Enable notifications" button that, when pressed, requests notification permissions for the app.
Read more >
Firebase crashes unity iOS app at startup - Google Groups
Using Firebase 3.0.1 Unity SDK and Unity 5.1.1p3. We built out fine to Android and were ... Finally found where you could get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found