transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.43k stars 191 forks source link

[Expo] iOS crash on runtime when the first start #475

Closed socheatleang closed 5 months ago

socheatleang commented 5 months ago

I have followed the install expo instruction. Everything works as expected for the android. However it always crash for the iOS on runtime (I got the build successfully).

Your Environment

Expected Behavior

It supposes to get running as normal like android.

Actual Behavior

It crash on runtime. I got the successfully build with the eas build. Yet after installed the app then I get crash when the app open. So I jump in to debug the native with the npx expo prebuild. Then I realize that I need to comment the [[TSBackgroundFetch sharedInstance] didFinishLaunching]; out from the AppDelegate.mm in order to get it run without crashing.

Steps to Reproduce

1. 2. 3. 4.

Context

I have tried to switch different version of react-native-backgorund-fetch but it stills.

Debug logs [I run it from xcode after do npx expo prebuild]

[TSBackgroundFetch load]: (
)
[TSBGAppRefreshSubscriber load]: {
}
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x2805d1890'
*** First throw call stack:
(0x1a9fa65e0 0x1a22d7c00 0x1aa036eec 0x1a9eeb7a8 0x1aa02c860 0x10179b7d0 0x10051dbfc 0x1ac2e0184 0x1ac2df2ec 0x1ac2de2d0 0x1ac2ddf1c 0x1ac25a988 0x1ac2e1eac 0x1ac206d7c 0x1ac2057f4 0x1ac20515c 0x1ac20502c 0x1ac204f34 0x1ac2047bc 0x1ac20446c 0x1ac58387c 0x1ac2035f0 0x1ac203460 0x1ac31e3d4 0x1ac31e16c 0x1c1fcdaa8 0x1c1fcd944 0x1c1fcc5a8 0x1c1fd8360 0x105cd2b34 0x105cd6530 0x1c1fc89ec 0x1c1fc896c 0x1c1fc8844 0x1a9ef0acc 0x1a9eefd48 0x1a9eee55c 0x1a9eed238 0x1a9eece18 0x1ec9b15ec 0x1ac2fb2fc 0x1ac2fa938 0x10051e354 0x1cc6d7d44)
libc++abi: terminating due to uncaught exception of type NSException

Config file

export default {
  name: process.env.APP_NAME,
  orientation: 'portrait',
  icon: process.env.APP_ICON_PATH,
  updates: {
    fallbackToCacheTimeout: 0,
  },
  assetBundlePatterns: ['**/*'],
  ios: {
    infoPlist: {
      NSLocationWhenInUseUsageDescription:
        'We need to access your location to locate you on the map if you need to',
      NSLocationAlwaysAndWhenInUseUsageDescription:
        'The XX App requires location in the background',
      NSMotionUsageDescription:
        'The XX App uses motion-detection to determine the motion-activity of the device (walking, vehicle, bicycle, etc)',
      UIBackgroundModes: ['location', 'fetch', 'processing', 'audio'],
      BGTaskSchedulerPermittedIdentifiers: [
        'com.transistorsoft.fetch',
        'com.transistorsoft.customtask',
      ],
    },
    entitlements: {
      'com.apple.developer.healthkit': true,
      'com.apple.developer.healthkit.background-delivery': true,
    },
  },
  plugins: [
     [
      'react-native-background-geolocation',
      {
        license: xxxx
      },
    ],
     ['react-native-background-fetch']
   ],
};
christocracy commented 5 months ago

You say you've followed the instructions but not provided any proof.

Where is your config file?

socheatleang commented 5 months ago

@christocracy . The issue updated with the config file.

christocracy commented 5 months ago

Since you're building this locally, post your Info.plist.

socheatleang commented 5 months ago

@christocracy Here is our info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>BGTaskSchedulerPermittedIdentifiers</key>
    <string>co.tryterra.data.post.request</string>
    <key>CFBundleAllowMixedLocalizations</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>xxxx</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
    <key>CFBundleShortVersionString</key>
    <string>0.5.2</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>com.googleusercontent.apps.xxx</string>
        </array>
      </dict>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>exp+defit</string>
        </array>
      </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>GMSApiKey</key>
    <string>xxxx</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>huobiwallet</string>
      <string>bitkeep</string>
      <string>ledgerlive</string>
      <string>cryptowallet</string>
      <string>metamask</string>
      <string>trust</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
      <key>NSExceptionDomains</key>
      <dict>
        <key>localhost</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
      </dict>
    </dict>
    <key>NSCameraUsageDescription</key>
    <string>X would like to access your camera for your profile photo upload. Your photos won't be shared without your permission.</string>
    <key>NSHealthShareUsageDescription</key>
    <string>undefined would like to access your Health Records in order to improve wellness.</string>
    <key>NSHealthUpdateUsageDescription</key>
    <string>undefined would like to update your Health Records in order to improve wellness.</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>The X App requires location in the background</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>We need to access your location to locate you on the map if you need to</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Allow $(PRODUCT_NAME) to access your microphone</string>
    <key>NSMotionUsageDescription</key>
    <string>The X App uses motion-detection to determine the motion-activity of the device (walking, vehicle, bicycle, etc)</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>APP would like to access your photo gallery for your profile photo upload. Your photos won't be shared without your permission.</string>
    <key>UIBackgroundModes</key>
    <array>
      <string>location</string>
      <string>fetch</string>
      <string>processing</string>
      <string>audio</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>SplashScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
      <string>armv7</string>
    </array>
    <key>UIRequiresFullScreen</key>
    <false/>
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleDefault</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIUserInterfaceStyle</key>
    <string>Light</string>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
  </dict>
</plist>
christocracy commented 5 months ago

Compare your BGTaskSchedulerPermittedIdentifiers in your expo config:

BGTaskSchedulerPermittedIdentifiers: [
    'com.transistorsoft.fetch',
    'com.transistorsoft.customtask',
],

vs that declared in your Info.plist (invalid):

<key>BGTaskSchedulerPermittedIdentifiers</key>
<string>co.tryterra.data.post.request</string>

The BGTaskSchedulerPermittedIdentifiers item is required to be of type <array> (as documented by Apple), for example:

  <key>BGTaskSchedulerPermittedIdentifiers</key>
  <array>
    <string>com.transistorsoft.fetch</string>
    <string>com.transistorsoft.customtask</string>
  </array>

That's why the compiler emits an error "NSInvalidArgumentException" -- it's trying to consume an <array> while you're providing it a <string>