achorein / expo-share-intent

🚀 Simple share intent in an Expo Native Module
MIT License
119 stars 10 forks source link

Crashes immediately when multiple schemes are defined #64

Closed betabites closed 1 month ago

betabites commented 1 month ago

Describe the bug Share intent crashes immediately on iOS when multiple schemes are defined.

To Reproduce Define multiple schemes in your app.json file. https://docs.expo.dev/versions/latest/config/app/#scheme

Environment

info Fetching system and libraries information...
System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M2
  Memory: 79.05 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.9.0
    path: ~/.nvm/versions/node/v20.9.0/bin/node
  Yarn:
    version: 1.22.21
    path: /usr/local/bin/yarn
  npm:
    version: 10.1.0
    path: ~/.nvm/versions/node/v20.9.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2021.3 AI-213.7172.25.2113.9123335
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java: Not Found
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.1
    wanted: 0.74.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Additional context Defining the scheme in the <ShareIntentProvider> seems to fix the issue while using the iOS simulator. Though the issue persists on a physical iOS device? No clue how this happens, but it does.

<ShareIntentProvider
            options={{
                debug: true,
                scheme: "<scheme here>",
                onResetShareIntent: () => {
                    // ...
                }
            }}
        >

According to one of the crash reports, it looks like the issue might be getting caused here, though I'm unsure how to resolve it permanently. And in a way that solves it on all devices.

Thread 7 Crashed::  Dispatch queue: com.apple.Foundation.NSItemProvider-callback-queue
0   ShareExtension                         0x102680cf8 Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value + 0 [inlined]
1   ShareExtension                         0x102680cf8 ShareViewController.redirectToHostApp(type:) + 1240 (ShareViewController.swift:237)
2   ShareExtension                         0x10267ee84 closure #1 in ShareViewController.handleImages(content:attachment:index:) + 3584 (ShareViewController.swift:129)
3   ShareExtension                         0x10267dbb4 thunk for @escaping @callee_guaranteed @Sendable (@guaranteed NSSecureCoding?, @guaranteed Error?) -> () + 72
4   Foundation                             0x180de3ab0 __95-[NSItemProvider _loadItemOfClass:forTypeIdentifier:options:coerceForCoding:completionHandler:]_block_invoke_12 + 188
5   libdispatch.dylib                      0x180170104 _dispatch_call_block_and_release + 24
6   libdispatch.dylib                      0x180171978 _dispatch_client_callout + 16
7   libdispatch.dylib                      0x180179b10 _dispatch_lane_serial_drain + 960
8   libdispatch.dylib                      0x18017a688 _dispatch_lane_invoke + 388
9   libdispatch.dylib                      0x180185a84 _dispatch_root_queue_drain_deferred_wlh + 276
10  libdispatch.dylib                      0x1801850d0 _dispatch_workloop_worker_thread + 448
11  libsystem_pthread.dylib                0x1027d3814 _pthread_wqthread + 284
12  libsystem_pthread.dylib                0x1027d25d4 start_wqthread + 8
achorein commented 1 month ago

I need to add the support for multiple scheme, I didn't know it was possible to do that. added in my TODO

achorein commented 1 month ago

According to one of the crash reports, it looks like the issue might be getting caused here, though I'm unsure how to resolve it permanently. And in a way that solves it on all devices.

@betabites good catch ! on iOS we need to open the app using the deeplink url : myapp://, if we have more than one scheme it didn't know which one to use. Getting the first scheme should work properly

app.json :

  "scheme": ["myapp1", "myapp2"]

then inject scheme[0] into ShareExtensionViewController.swift (eg: let shareProtocol = "myapp1")

achorein commented 1 month ago

available in v2.1.0

betabites commented 3 weeks ago

I need to keep more up-to-date with my GitHub. Amazing! Thank You :)