Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission request for notification in SDK 37 crashes on iOS device #7562

Closed
pdugan20 opened this issue Apr 1, 2020 · 11 comments · Fixed by #7584
Closed

Permission request for notification in SDK 37 crashes on iOS device #7562

pdugan20 opened this issue Apr 1, 2020 · 11 comments · Fixed by #7584
Assignees

Comments

@pdugan20
Copy link

pdugan20 commented Apr 1, 2020

🐛 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

@sjchmiela
Copy link
Contributor

If it's a crash from TestFlight I presume the crash happens in standalone apps, right? Have you noticed it in Expo client too?

@pdugan20
Copy link
Author

pdugan20 commented Apr 1, 2020

const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

...returns 'undetermined' on the simulator (which I believe is expected) and displays the permissions prompt and returns 'granted' in the expo app on a physical device.

The crash is only happening within testflight for some reason and isn't being logged to Sentry. Was working fine on SDK 36 so it seems to have been upgrading to SDK 37 which caused the issue.

@sjchmiela
Copy link
Contributor

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.

@pdugan20
Copy link
Author

pdugan20 commented Apr 1, 2020

* 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._

This also crashed the app.

* 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_

Couldn't do this since it still crashed.

* 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?_

Yup, the app crashes every time I call:
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

...it never makes it to the permission prompt. Other permission prompts like the one for location work fine.

* 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._

Uninstalling, restarting, and then reinstalling from test flight produces the same bug.

Here's the full stack-trace from test flight if that's helpful:
testflight_feedback.zip

@sjchmiela sjchmiela self-assigned this Apr 1, 2020
@sjchmiela
Copy link
Contributor

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

@pdugan20
Copy link
Author

pdugan20 commented Apr 1, 2020

@sjchmiela you the man! thanks so much for such a fast turnaround!!

@sjchmiela
Copy link
Contributor

Hats off to @esamelson for quickly deploying the fix to Turtle builders! 🙇

I think if you would rebuild your app it shouldn't crash on the aforementioned code. Let me know if it does!

@pdugan20
Copy link
Author

pdugan20 commented Apr 2, 2020

Just rebuilt and can confirm it's now working as intended. Thanks @esamelson and @sjchmiela!

sjchmiela added a commit that referenced this issue Apr 29, 2020
# Why

While investigating reasons for #7562 I [found out](https://stackoverflow.com/a/13858628/1123156) it's not recommended to use `dispatch_once_t` as a property.

# How

- removed all `dispatch_once_t` uses in favor of simple `if (!…) { … =`

# Test Plan

Expo client compiled, running `native-component-list#Permissions` screen worked ok.
@bkoether
Copy link

bkoether commented Jun 2, 2020

@sjchmiela I'm still experience this issue with Location.requestPermissionsAsync()
Using SDK 37 and the latest version of the CLI. Build iOS app on Friday. Works just fine in iOS simulator, but the app crashes in TestFlight. Briefly shows the "Grant permissions" modal and the crashes. Other permissions work though, like access to photos or the camera.

@bkoether
Copy link

bkoether commented Jun 5, 2020

@sjchmiela Should I open another ticket for this? Still experiencing this issue with the location permissions.

@lkeshavan
Copy link

I crash simply by having this line in the Code import * as Permissions from 'expo-permissions';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants