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

image intent doesn't work for iOS when app is closed #310

Open
JackBeStrong opened this issue Jun 30, 2024 · 3 comments
Open

image intent doesn't work for iOS when app is closed #310

JackBeStrong opened this issue Jun 30, 2024 · 3 comments

Comments

@JackBeStrong
Copy link

How to reproduce:

I literally started a new project, just to test this out.

  1. I created a new project intent_test (flutter name)
  2. Used the example main.dart exactly.
  3. Followed the steps in iOS exactly, and I was able to get intent to work when the app is just minimized:
    IMG_4113

Now, if I swipe up, and close the app. And share the file again, the app just crashes, with the attached crash report.
Runner-2024-06-30-142648.txt

What have I done wrong or is this an actual issue with the package?

Below is my dart code:

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:receive_sharing_intent/receive_sharing_intent.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
@OverRide
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
late StreamSubscription _intentSub;
final _sharedFiles = [];

@OverRide
void initState() {
super.initState();

// Listen to media sharing coming from outside the app while the app is in the memory.
_intentSub = ReceiveSharingIntent.instance.getMediaStream().listen((value) {
  setState(() {
    _sharedFiles.clear();
    _sharedFiles.addAll(value);

    print(_sharedFiles.map((f) => f.toMap()));
  });
}, onError: (err) {
  print("getIntentDataStream error: $err");
});

// Get the media sharing coming from outside the app while the app is closed.
ReceiveSharingIntent.instance.getInitialMedia().then((value) {
  setState(() {
    _sharedFiles.clear();
    _sharedFiles.addAll(value);
    print(_sharedFiles.map((f) => f.toMap()));

    // Tell the library that we are done processing the intent.
    ReceiveSharingIntent.instance.reset();
  });
});

}

@OverRide
void dispose() {
_intentSub.cancel();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
const textStyleBold = const TextStyle(fontWeight: FontWeight.bold);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text("Shared files:", style: textStyleBold),
Text(_sharedFiles
.map((f) => f.toMap())
.join(",\n****************\n")),
],
),
),
),
);
}
}

Let me know if you need any additional information.

@JackBeStrong
Copy link
Author

I'd also want to add that Android works fine. It's just iOS when the app is closed, that it crashes. I feed the crash report to AI, and this is what I got:

The crash log you provided indicates that the app "Runner" encountered a segmentation fault (EXC_BAD_ACCESS) due to an invalid memory address (KERN_INVALID_ADDRESS at 0x0000000000000000). This typically happens when the app attempts to access memory that has not been allocated or is no longer valid.

Here are some key points from the crash log and potential areas to investigate:

Exception Codes:

The exception codes are 0x0000000000000001, 0x0000000000000000, indicating a segmentation fault at address 0x0000000000000000.
Faulting Thread:

The crash occurred in the main thread (thread 0).
The pc (program counter) value indicates the address where the crash happened: swift_getObjectType.
Relevant Symbols:

swift_getObjectType: This symbol appears to be where the crash originated, which is related to Swift object type retrieval.
static SwiftReceiveSharingIntentPlugin.register(with:): This method is part of the receive_sharing_intent plugin and is mentioned multiple times in the call stack.
Call Stack:

The call stack shows the sequence of method calls leading to the crash. Key methods include SwiftReceiveSharingIntentPlugin.register(with:) and GeneratedPluginRegistrant.registerWithRegistry.
Plugin Involvement:

The receive_sharing_intent plugin is heavily referenced in the call stack, suggesting that it might be the source of the issue.
Steps to Troubleshoot:
Check Plugin Registration:

Ensure that the receive_sharing_intent plugin is properly registered in the app. Verify that the plugin setup is correct in both the Dart and native code.
Inspect Plugin Code:

Review the implementation of the SwiftReceiveSharingIntentPlugin and ReceiveSharingIntentPlugin classes. Look for any potential issues with memory management or improper access to objects.
Verify Dependencies:

Ensure that all dependencies and plugins are up-to-date and compatible with your current Flutter and Dart versions.
Debugging:

Use breakpoints and logging to trace the execution flow in the SwiftReceiveSharingIntentPlugin.register(with:) method to pinpoint where the invalid memory access occurs.
Reproduce the Crash:

Try to reproduce the crash consistently by following the same steps or actions that led to the crash. This can help narrow down the exact cause.
Update iOS Version:

Ensure that you are testing on a device or simulator with the latest iOS version, as there might be fixes or improvements in newer releases.
By following these steps, you should be able to identify and resolve the cause of the crash in the Runner app related to the receive_sharing_intent plugin. If you need further assistance, consider reaching out to the plugin's maintainers or community for support.

@suzyvivi
Copy link

suzyvivi commented Aug 5, 2024

So are there any solutions ?

I have the same problem. When the app is cold started, it crashes. Looking at the crash report in iOS, I found that the information indicates that the crash occurred during the app startup process, specifically when registering the SwiftReceiveSharingIntentPlugin plugin. Here is a selection of the report:

"threads" : [
  {
    "triggered":true,
    "id":4078935,
    "threadState":{
      "pc":{"value":7288945876,"matchesCrashFrame":1},
      ...
    },
    "queue":"com.apple.main-thread",
    "frames":[
      {
        "imageOffset":4316372,
        "symbol":"swift_getObjectType",
        "symbolLocation":40,
        "imageIndex":0
      },
      {
        "imageOffset":4467464,
        "symbol":"static SwiftReceiveSharingIntentPlugin.register(with:)",
        "symbolLocation":152,
        "imageIndex":1
      },
      {
        "imageOffset":336888,
        "symbol":"AppDelegate.application(_:didFinishLaunchingWithOptions:)",
        "symbolLocation":148,
        "imageIndex":2
      },
      ...
    ]
  }
]

@xalanq
Copy link

xalanq commented Aug 23, 2024

+1

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

No branches or pull requests

3 participants