nativescript-community / perms

An unified permissions API for NativeScript on iOS and Android.
https://nativescript-community.github.io/perms/
Apache License 2.0
12 stars 9 forks source link

iOS - App crashes when I change permission from settings #15

Closed NCenerar closed 4 days ago

NCenerar commented 1 year ago

Hello ! I have been facing the "iOS - App crashes when I change permission from settings" issue

Q: iOS - App crashes when I change permission from settings A: This is normal. iOS restarts your app when your privacy settings change. Just google "iOS crash permission change"

After some investigation, it seems that this line is responsible for it and removing it seems to fix it.

https://github.com/nativescript-community/perms/blob/f0afedb76a36fe86c99fae4e4db3791c26ee3f92/src/perms/index.ios.ts#L570

Removing it make it works. Could this solution be investigated ?

To be complete, I open application settings with this:

const center = NSNotificationCenter.defaultCenter;
const mainQueue = NSOperationQueue.mainQueue;
return new Promise((resolve, reject) => {
    const observer = function (_: unknown) {
        resolve(true);
    };
    center.addObserverForNameObjectQueueUsingBlock(UIApplicationDidBecomeActiveNotification, null, mainQueue, observer);
    UIApplication.sharedApplication.openURL(NSURL.URLWithString(UIApplicationOpenSettingsURLString));
});

Thank you.

farfromrefug commented 1 year ago

@NCenerar not sure i understand. You say it is normal for the app to be killed. If that exact like crashes you must have an error while debugging through xcode. Can you sahre what it says? Can you also share the flow. Like what are you changing in the settings when it crashes?

NCenerar commented 1 year ago

Thank you for your response @farfromrefug Well, I don't say it is normal to crash, it was a quote from the README of this repo 😅 https://github.com/nativescript-community/perms#q-ios---app-crashes-when-i-change-permission-from-settings

The thing is: even if I don't change a thing in the settings, just opening the setting from the method call and going back to the app make it crash. I suspect that the reference to the center is not available anymore or maybe the reference to the observer 🤷

  ====== Assertion failed ======
  Native stack trace:
  1          0x10692b1f4 tns::Assert(bool, v8::Isolate*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 164
  2          0x10694b470 tns::Interop::WriteValue(v8::Local<v8::Context>, tns::TypeEncoding const*, void*, v8::Local<v8::Value>) + 6380
  3          0x106949b60 tns::Interop::SetFFIParams(v8::Local<v8::Context>, tns::TypeEncoding const*, tns::FFICall*, int, int, tns::V8Args&) + 120
  4          0x106949738 tns::Interop::CallFunctionInternal(tns::MethodCall&) + 304
  5          0x1068ab964 tns::ArgConverter::Invoke(v8::Local<v8::Context>, objc_class*, v8::Local<v8::Object>, tns::V8Args&, tns::MethodMeta const*, bool) + 1104
  6          0x106903e28 tns::MetadataBuilder::InvokeMethod(v8::Local<v8::Context>, tns::MethodMeta const*, v8::Local<v8::Object>, tns::V8Args&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool) + 88
  7          0x106903498 tns::MetadataBuilder::MethodCallback(v8::FunctionCallbackInfo<v8::Value> const&) + 220
  8          0x106a3c0e4 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) + 544
  9          0x106a3b5e4 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) + 524
  10         0x106a3ad7c v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) + 228
  11         0x10711644c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit + 108
  12         0x1070af618 Builtins_InterpreterEntryTrampoline + 248
  13         0x1070ad3ec Builtins_JSEntryTrampoline + 172
  14         0x1070ad084 Builtins_JSEntry + 164
  15         0x106b87cdc v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 2532
  16         0x106b872c4 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 216
  17         0x1069da780 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) + 448
  18         0x1068ad274 tns::ArgConverter::MethodCallback(ffi_cif*, void*, void**, void*) + 1224
  19         0x1069a7d7c ffi_closure_SYSV_inner + 800
  20         0x1069a81b4 .Ldo_closure + 20
  21         0x18289c1bc <redacted> + 316
  22         0x18117e22c <redacted> + 20
  23         0x181213850 <redacted> + 48
  24         0x1811e8b68 <redacted> + 416
  25         0x181192fc0 _CFXNotificationPost + 708
  26         0x18288300c <redacted> + 92
  27         0x1837474c0 <redacted> + 1612
  28         0x18386405c <redacted> + 324
  29         0x183a8c434 <redacted> + 744
  30         0x183a1c174 <redacted> + 336
  31         0x18362cd44 <redacted> + 188
  32         0x1836e8934 <redacted> + 812
  33         0x18362ead4 _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 248
  34         0x183713184 <redacted> + 356
  35         0x183b68f38 <redacted> + 772
  36         0x18365c77c <redacted> + 248
  37         0x18369e51c <redacted> + 264
  38         0x18362ae38 <redacted> + 448
  39         0x192351328 <redacted> + 500
  40         0x19236815c <redacted> + 124
  41         0x19234ebdc <redacted> + 232
  42         0x192354a68 <redacted> + 368
  43         0x180ea8094 <redacted> + 16
  44         0x180e4b150 <redacted> + 220
  45         0x1923502ac <redacted> + 40
  46         0x19234f7c0 <redacted> + 176
  47         0x192353960 <redacted> + 24
  48         0x181208468 <redacted> + 24
  49         0x181218598 <redacted> + 204
  50         0x18115a774 <redacted> + 256
  51         0x18115fe48 <redacted> + 768
  52         0x181173194 CFRunLoopRunSpecific + 572
  53         0x1a1ca6988 GSEventRunModal + 160
  54         0x183975a88 <redacted> + 1080
  55         0x18370efc8 UIApplicationMain + 336
  56         0x1069a8044 ffi_call_SYSV + 68
  57         0x1069a75e0 ffi_call_int + 968
  58         0x106949780 tns::Interop::CallFunctionInternal(tns::MethodCall&) + 376
  59         0x106909148 std::__1::__function::__func<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2, std::__1::allocator<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2>, void ()>::operator()() + 620
  60         0x10696e7dc tns::Tasks::Drain() + 100
  61         0x104c73f00 main + 628
  62         0x1055e04d0 62  dyld                                0x00000001055e04d0 start + 444
  JavaScript stack trace:
  at observer (file: app/webpack:/..../node_modules/@nativescript-community/perms/index.ios.js:594:0)
dankhan commented 1 year ago

Running into the same issue here.

Tested with canOpenSettings() first in my app, and then calling openSettings() and changing nothing - when using the native back link iOS has at the top of the window it causes the app to crash, and outputs this stack trace in the nativescript log:

====== Assertion failed ======
  Native stack trace:
  1          0x10633fcf0 tns::Assert(bool, v8::Isolate*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 164
  2          0x10635ac50 tns::Interop::WriteValue(v8::Local<v8::Context>, tns::TypeEncoding const*, void*, v8::Local<v8::Value>) + 6348
  3          0x106359360 tns::Interop::SetFFIParams(v8::Local<v8::Context>, tns::TypeEncoding const*, tns::FFICall*, int, int, tns::V8Args&) + 120
  4          0x106358f38 tns::Interop::CallFunctionInternal(tns::MethodCall&) + 304
  5          0x106303840 tns::ArgConverter::Invoke(v8::Local<v8::Context>, objc_class*, v8::Local<v8::Object>, tns::V8Args&, tns::MethodMeta const*, bool) + 1096
  6          0x106324988 tns::MetadataBuilder::InvokeMethod(v8::Local<v8::Context>, tns::MethodMeta const*, v8::Local<v8::Object>, tns::V8Args&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool) + 88
  7          0x106323e34 tns::MetadataBuilder::MethodCallback(v8::FunctionCallbackInfo<v8::Value> const&) + 220
  8          0x106443d50 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) + 276
  9          0x10644338c v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) + 504
  10         0x106442b28 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) + 240
  11         0x106cc5f4c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit + 108
  12         0x106c53e58 Builtins_InterpreterEntryTrampoline + 248
  13         0x106c52190 Builtins_JSEntryTrampoline + 176
  14         0x106c51e24 Builtins_JSEntry + 164
  15         0x106612fa0 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 2680
  16         0x1066124f4 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 212
  17         0x1063c487c v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) + 652
  18         0x1063051a0 tns::ArgConverter::MethodCallback(ffi_cif*, void*, void**, void*) + 1384
  19         0x106371a9c ffi_closure_SYSV_inner + 796
  20         0x1063741b4 .Ldo_closure + 20
  21         0x18036bfe4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 120
  22         0x18036bf1c ___CFXRegistrationPost_block_invoke + 84
  23         0x18036b424 _CFXRegistrationPost + 404
  24         0x18036ae10 _CFXNotificationPost + 664
  25         0x180b5309c -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
  26         0x10e47eab4 -[UIApplication _stopDeactivatingForReason:] + 1184
  27         0x10dbda6c8 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 272
  28         0x10dbda97c -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 588
  29         0x10dbda374 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 248
  30         0x10dbe5910 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 140
  31         0x10dfbd6d4 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 656
  32         0x10e0bd0d4 _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 196
  33         0x10dbe561c -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 288
  34         0x10da50b3c __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.196 + 552
  35         0x10da4f93c -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 208
  36         0x10da507f8 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 220
  37         0x10dfe35d8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 308
  38         0x184e593d4 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 392
  39         0x184e810d0 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 124
  40         0x184e64704 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
  41         0x184e8101c __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 312
  42         0x180134708 _dispatch_client_callout + 16
  43         0x180138644 _dispatch_block_invoke_direct + 376
  44         0x184e9ef14 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
  45         0x184e9ee08 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 176
  46         0x184e9ef48 -[FBSSerialQueue _performNextFromRunLoopSource] + 24
  47         0x18039ac6c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
  48         0x18039abb4 __CFRunLoopDoSource0 + 172
  49         0x18039a324 __CFRunLoopDoSources0 + 232
  50         0x180394958 __CFRunLoopRun + 748
  51         0x180394254 CFRunLoopRunSpecific + 584
  52         0x188eb7c9c GSEventRunModal + 160
  53         0x10e482ff0 -[UIApplication _run] + 868
  54         0x10e486f3c UIApplicationMain + 124
  55         0x106374044 ffi_call_SYSV + 68
  56         0x106371300 ffi_call_int + 972
  57         0x106358f80 tns::Interop::CallFunctionInternal(tns::MethodCall&) + 376
  58         0x106329f24 std::__1::__function::__func<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2, std::__1::allocator<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2>, void ()>::operator()() + 616
  59         0x1063625ac tns::Tasks::Drain() + 100
  60         0x102eabbd4 main + 636
  61         0x1039f5514 61  dyld                                0x00000001039f5514 start_sim + 20
  62         0x103ab9f28 62  ???                                 0x0000000103ab9f28 0x0 + 4356546344
  63  0x257d800000000000 63  ???                                 0x257d800000000000 0x0 + 2701456088980520960
  JavaScript stack trace:
  at observer (file: app/webpack:/.../node_modules/@nativescript-community/perms/index.ios.js:594:0)
fpaaske commented 10 months ago

I got the exact same issue on my app. Any chance this can be fixed?

  ====== Assertion failed ======
  Native stack trace:
  1          0x1073549d0 tns::Assert(bool, v8::Isolate*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 164
  2          0x10736fbec tns::Interop::WriteValue(v8::Local<v8::Context>, tns::TypeEncoding const*, void*, v8::Local<v8::Value>) + 6452
  3          0x10736e294 tns::Interop::SetFFIParams(v8::Local<v8::Context>, tns::TypeEncoding const*, tns::FFICall*, int, int, tns::V8Args&) + 120
  4          0x10736de6c tns::Interop::CallFunctionInternal(tns::MethodCall&) + 304
  5          0x1073179bc tns::ArgConverter::Invoke(v8::Local<v8::Context>, objc_class*, v8::Local<v8::Object>, tns::V8Args&, tns::MethodMeta const*, bool) + 1104
  6          0x107339118 tns::MetadataBuilder::InvokeMethod(v8::Local<v8::Context>, tns::MethodMeta const*, v8::Local<v8::Object>, tns::V8Args&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool) + 88
  7          0x1073385c4 tns::MetadataBuilder::MethodCallback(v8::FunctionCallbackInfo<v8::Value> const&) + 220
  8          0x1074576cc v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) + 276
  9          0x107456d08 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) + 504
  10         0x1074564a4 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) + 240
  11         0x107ce1f4c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit + 108
  12         0x107c6fe58 Builtins_InterpreterEntryTrampoline + 248
  13         0x107c6e190 Builtins_JSEntryTrampoline + 176
  14         0x107c6de24 Builtins_JSEntry + 164
  15         0x1076278c4 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 2680
  16         0x107626e18 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 212
  17         0x1073d7f70 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) + 652
  18         0x1073193c4 tns::ArgConverter::MethodCallback(ffi_cif*, void*, void**, void*) + 1424
  19         0x107386c28 ffi_closure_SYSV_inner + 800
  20         0x1073881b4 .Ldo_closure + 20
  21         0x1a7d092c4 <redacted> + 128
  22         0x1a7d08ca0 <redacted> + 88
  23         0x1a7d08be8 <redacted> + 440
  24         0x1a7d08138 _CFXNotificationPost + 724
  25         0x1a6c9e7a4 <redacted> + 92
  26         0x1aa091700 <redacted> + 1240
  27         0x1aa03fc1c <redacted> + 280
  28         0x1aa03e658 <redacted> + 608
  29         0x1aa03dfc0 <redacted> + 248
  30         0x1aa03de90 <redacted> + 148
  31         0x1aa03dd98 <redacted> + 736
  32         0x1aa03d620 _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 224
  33         0x1aa03d2d0 <redacted> + 316
  34         0x1aa3c10a8 <redacted> + 612
  35         0x1aa03c454 <redacted> + 216
  36         0x1aa03c2c4 <redacted> + 244
  37         0x1aa03c104 <redacted> + 336
  38         0x1c016c5b4 <redacted> + 660
  39         0x1c016c300 <redacted> + 152
  40         0x1c016c19c <redacted> + 168
  41         0x1c016c0b8 <redacted> + 344
  42         0x1afccd300 <redacted> + 20
  43         0x1afcd0d48 <redacted> + 284
  44         0x1c0168520 <redacted> + 52
  45         0x1c01684a0 <redacted> + 240
  46         0x1c0168378 <redacted> + 28
  47         0x1a7d1112c <redacted> + 28
  48         0x1a7d103a8 <redacted> + 176
  49         0x1a7d0eb5c <redacted> + 244
  50         0x1a7d0d898 <redacted> + 828
  51         0x1a7d0d478 CFRunLoopRunSpecific + 608
  52         0x1eb2664f8 GSEventRunModal + 164
  53         0x1aa13162c <redacted> + 888
  54         0x1aa130c68 UIApplicationMain + 340
  55         0x107388044 ffi_call_SYSV + 68
  56         0x10738648c ffi_call_int + 968
  57         0x10736deb4 tns::Interop::CallFunctionInternal(tns::MethodCall&) + 376
  58         0x10733e7e8 std::__1::__function::__func<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2, std::__1::allocator<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2>, void ()>::operator()() + 632
  59         0x1073776f4 tns::Tasks::Drain() + 100
  60         0x104c5027c main + 636
  61         0x1caa32dcc <redacted> + 2240
  JavaScript stack trace:
  at observer (file: src/webpack:/app/node_modules/@nativescript-community/perms/index.ios.js:594:23)
farfromrefug commented 10 months ago

@fpaaske could you show me the code of @nativescript-community/perms/index.ios.js:594:23. not only the line but a bit before and after

fpaaske commented 10 months ago

@farfromrefug It's this line: https://github.com/nativescript-community/perms/blob/aa4aa4236df7f23c85bd83afec0a345a8fae8023/src/perms/index.ios.ts#L570

cristiandaulisio commented 3 weeks ago

news?

farfromrefug commented 3 weeks ago

@cristiandaulisio @fpaaske @NCenerar i published a new version which should fix it

fpaaske commented 4 days ago

@farfromrefug I can confirm this is fixed now, at least I cannot reproduce this issue anymore. Thanks!