NativeScript / ios

NativeScript for iOS and visionOS using V8
https://docs.nativescript.org/guide/ios-marshalling
131 stars 33 forks source link

IOS: calling exit(0) results in "Appname Crashed" error message #217

Closed cjohn001 closed 1 year ago

cjohn001 commented 1 year ago

Issue Description

I need to reconfigure and restart my app in certain situations, for example on timezone changes. So far I called exit(0) on IOS. However, since upgrading to

"@nativescript/core": "8.5.0",

This now results in the app crashing with the familiar ios dialog and error message "appname Crahsed Do you want to share additional information with the developer? "

Reproduction

call

exit(0)

Relevant log output (if applicable)

No response

Environment

OS: macOS 13.4
CPU: (10) arm64 Apple M1 Pro
Shell: /bin/zsh
node: 18.12.1
npm: 8.19.2
nativescript: 8.5.3

# android
java: 11.0.18
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 14.3/14E222b
cocoapods: 1.12.0
python: 3.11.2
python3: 3.11.2
ruby: 2.7.7
platforms: 
  - DriverKit 22.4
  - iOS 16.4
  - macOS 13.3
  - tvOS 16.4
  - watchOS 9.4

Dependencies

"dependencies": {
  "@angular/animations": "16.0.3",
  "@angular/common": "16.0.3",
  "@angular/compiler": "16.0.3",
  "@angular/core": "16.0.3",
  "@angular/forms": "16.0.3",
  "@angular/platform-browser": "16.0.3",
  "@angular/platform-browser-dynamic": "16.0.3",
  "@angular/router": "16.0.3",
  "@apollo/client": "3.7.14",
  "@mnd/external-web-view": "file:../mnd-plugins/dist/packages/external-web-view/mnd-external-web-view-1.0.0.tgz",
  "@nativescript/angular": "16.0.0",
  "@nativescript/core": "8.5.3",
  "@nativescript/iqkeyboardmanager": "2.1.1",
  "@nativescript/localize": "5.1.0",
  "@nativescript/mlkit-barcode-scanning": "2.0.0",
  "@nativescript/mlkit-core": "2.0.0",
  "@nativescript/secure-storage": "3.0.0",
  "@nativescript/theme": "3.0.2",
  "@nativescript/ui-charts": "0.2.4",
  "apollo-angular": "5.0.0",
  "apollo3-cache-persist": "0.14.1",
  "d3-ease": "3.0.1",
  "graphql": "16.6.0",
  "graphql-tag": "2.12.6",
  "intl": "1.2.5",
  "moment": "2.29.4",
  "nativescript-health-data": "file:../mnd-custom-plugins/nativescript-health-data/publish/package/nativescript-health-data-2.0.0.tgz",
  "nativescript-oauth2-ext": "file:../mnd-custom-plugins/nativescript-oauth2-ext/publish/package/nativescript-oauth2-ext-3.0.1.tgz",
  "nativescript-sqlite": "2.8.6",
  "nativescript-ui-calendar": "15.2.3",
  "nativescript-ui-gauge": "15.2.3",
  "rxjs": "7.8.1",
  "uuid": "9.0.0",
  "zone.js": "0.13.0"
},
"devDependencies": {
  "@angular-devkit/build-angular": "16.0.3",
  "@angular/compiler-cli": "16.0.3",
  "@graphql-codegen/cli": "4.0.0",
  "@graphql-codegen/fragment-matcher": "5.0.0",
  "@graphql-codegen/introspection": "4.0.0",
  "@graphql-codegen/typescript": "4.0.0",
  "@graphql-codegen/typescript-apollo-angular": "3.5.6",
  "@graphql-codegen/typescript-operations": "4.0.0",
  "@nativescript/android": "8.5.0",
  "@nativescript/ios": "8.5.2",
  "@nativescript/types": "8.5.0",
  "@nativescript/webpack": "5.0.14",
  "@ngtools/webpack": "16.0.3",
  "@types/d3-ease": "3.0.0",
  "@types/intl": "1.2.0",
  "@types/node": "20.2.5",
  "@types/uuid": "9.0.1",
  "keycloak-request-token": "0.1.0",
  "rimraf": "5.0.1",
  "sass": "1.62.1",
  "ts-node": "10.9.1",
  "typescript": "4.9.5"
}

Please accept these terms

CatchABus commented 1 year ago

Have you got any worker running in your app? If so, are you terminating it before calling exit?

cjohn001 commented 1 year ago

@CatchABus : No I do not have any workers running. The logic is triggered when pressing a button

buttonPressed(){
  setTimeout(() => {
      if (global.isAndroid) {
        android.os.Process.killProcess(android.os.Process.myPid());
      } else {
    exit(0);
      }
  },100);
}
CatchABus commented 1 year ago

@CatchABus : No I do not have any workers running. The logic is triggered when pressing a button

buttonPressed(){
  setTimeout(() => {
      if (global.isAndroid) {
        android.os.Process.killProcess(android.os.Process.myPid());
      } else {
  exit(0);
      }
  },100);
}

I see. Thanks for clarification. Please post the error message when possible. There might be useful information in it.

cjohn001 commented 1 year ago

@CatchABus : attached the error dialog

23-05-31 18-59-20 0173

CatchABus commented 1 year ago

@CatchABus : attached the error dialog

23-05-31 18-59-20 0173

Are you running app using ns run or ns debug? App will display additional trace if installed and ran with one of those.

shirakaba commented 1 year ago

Note that it is against App Store rules for iOS apps to force an exit. Regardless of whether NativeScript is exhibiting expected behaviour, it would be best to find another way to handle refreshing your state.

Oddly, macOS apps are allowed to do it, mainly just in relation to refreshing some state related to in-app-purchases handling, though.

cjohn001 commented 1 year ago

@shirakaba : Thanks for pointing this out. My problem is that timezone changes seem to not be applied to the nativescript runtime. So doing new Date().getTimezoneOffset().toString(); before and after timezone change results in the same offset. Only after restart of the app the new timezone is correctly applied. Please note, when I say after timezone change I mean, that I have put a check on app reactivation where I test for time zone changes:

Application.on(Application.resumeEvent,...

Maybe I should add another bug report in regards to timezone changes?

cjohn001 commented 1 year ago

@CatchABus : I am unfortunately only seeing the bug when running the release build. Both ns debug and ns run on device do not lead to the issue.

cjohn001 commented 1 year ago

@CatchABus : Have you been able to recreate the issue?

rigor789 commented 1 year ago

I believe this is fixed by https://github.com/NativeScript/ios/commit/5a6c2ee5efa0c557c94ae56da0d3b3a31911d1b8

Can try with:

npm i --save-dev @nativescript/ios@8.5.3-next.2023-06-12-5243995962
ns clean
ns run ios
cjohn001 commented 1 year ago

@rigor789 : Great job, version @nativescript/ios@8.5.3-next.2023-06-12-5243995962 indeed does fix the issue. Shall I keep the issue open till 8.5.3 was released?