send-intent icon indicating copy to clipboard operation
send-intent copied to clipboard

Plugin working fine in android but not working in ios

Open alishhid opened this issue 1 year ago • 17 comments

Actually the issue is configuration provided in the plugin documentation for ios is not working. i have added the configuration in info.plist but still my app is not appearing in mobile sharelist.

alishhid avatar Feb 29 '24 12:02 alishhid

Did you walk through all the steps describe in README? You need to ceate a "Share Extension", register your URL Scheme and create an app group.

carsten-klaffke avatar Mar 08 '24 13:03 carsten-klaffke

I'm having a similar issue, and my first bet is I have something odd in my config. But I have a question. Should I see my app listed as a share target in the iOS simulator or does the simulator have any kind of limitation for this to work? I don't have a real device handy so I was wondering if I should be able to operate normally with the send-intent plugin provided that I have my config properly implemented.

markelarizaga avatar Apr 02 '24 23:04 markelarizaga

Hello @markelarizaga , yes, you should see it in the virtual device, too. The example app should be working on iOS (SendIntentExample) and should illustrate a complete configuration. You see the SendIntentExample-option in the image scrrenshot below (Virtual Device).

Simulator Screenshot - iPhone 15 Pro - 2024-04-03 at 09 24 26

carsten-klaffke avatar Apr 03 '24 07:04 carsten-klaffke

Hi again, I installed the example app in my simulator, which simulates an iPhone 15 Pro with iOS 16.2, and when trying to share a webpage via Safari, I see this:

Screenshot 2024-04-09 at 01 04 35

As you see the example app is not listed for some reason. My understanding is that just checking out the example code, building it in Xcode and running it should be enough, right? I don't need to change any groups, url schemes or anything, correct?

markelarizaga avatar Apr 08 '24 23:04 markelarizaga

Hello @markelarizaga, might be a stupid question but did you try clicking on "... mas"? If it is really not listed, maybe signing is a problem. This is configured individually in XCode (Targets -> Signing and Capabilities).

carsten-klaffke avatar Apr 09 '24 06:04 carsten-klaffke

Haha, it's not a stupid question at all, but yes, I tried clicking in Más (which for context means More in Spanish) but the app is not there either. As you say, I tend to think on something around the app config on my side. I will keep trying. Thanks a lot for your quick responses.

markelarizaga avatar Apr 09 '24 07:04 markelarizaga

Please check out this thread 80 as it covers some potential problems with signing and deployment target!

carsten-klaffke avatar Apr 09 '24 07:04 carsten-klaffke

I just realized I never answered back. I finally made it and my app appears among the share targets in iOS. It was something in the app config to be tweaked in Xcode. However, now I am facing a different issue. When sharing, say, a website from safari, my app opens correctly but the object passed to handleIntent contains only empty values:

 window.addEventListener("sendIntentReceived", () => {
        SendIntent.checkSendIntentReceived()
            .then(handleIntent)
            .catch(handleError);
    });

function handleIntent(result) {
    // result is { title: "", description: "", type: "", url: "", additional-terms: "" }
}

Any clue? I gave a look to the swift code in the documentation and the closest thing I see that could generate such an object is this:

let queryItems = shareItems.map {
            [
                URLQueryItem(
                    name: "title",
                    value: $0.title?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""),
                URLQueryItem(name: "description", value: ""),
                URLQueryItem(
                    name: "type",
                    value: $0.type?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""),
                URLQueryItem(
                    name: "url",
                    value: $0.url?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""),
            ]
        }.flatMap({ $0 })

Unfortunately I never worked with Swift so everything I can make are guesses. Let me know if you prefer to open a new issue @carsten-klaffke .

markelarizaga avatar Jun 18 '24 00:06 markelarizaga

It's hard to tell what is going wrong from here. You could debug or log some code positions to see where the info is getting lost. For this, I would suggest:

  1. ShareViewController::sendData(), check queryItems (just as you already pointed out yourself)
  2. AppDelegate::application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) , check if params are arriving properly
  3. SendIntent::checkSendIntentReceived(), check if "firstItem" in store holds the correct values

carsten-klaffke avatar Jun 19 '24 07:06 carsten-klaffke

Will do! Thanks again for the help.

markelarizaga avatar Jun 19 '24 07:06 markelarizaga

Ok, I tried debugging the share action.

I see sendData function gets values that make sense (I'm sharing a webpage from Safari): Screenshot 2024-06-25 at 00 17 31

However, the app doesn't seem to stop in the app delegate. I'm seeing this in Xcode when I set a line to debug: Screenshot 2024-06-25 at 00 22 42

And it says something like: Xcode won't stop in this line because it has not been resolved. Can it be there is something in my config that is making the app not run that code?

I also spotted a difference between my code and the docs/examples in this repo. In AppDelegate, this line:

let store = ShareStore.store

Was causing a compilation error: "Cannot find 'ShareStore' in scope".

I overcome the build error this causes by adding the following code into the file:

public final class ShareStore {

    public static let store = ShareStore()

    private init() {
        self.shareItems = []
        self.processed = false
    }

    public var shareItems: [JSObject]

    public var processed: Bool
}

Honestly I don't know how I reached this code, but it makes the build error disapear and run the app. Can this be related to my problem?

markelarizaga avatar Jun 24 '24 22:06 markelarizaga

I would assume that the new definition of ShareStore is causing the problem. You are writing to the wrong object, so the plugin can't read the data. Your AppDelegate::application(...)-call should be fine, as the "sendIntentReceived"-event is fired and catched properly in your JS-Code. So don't worry about the breakpoint that doesn't cause a stop (probably a non-debuggable line)! To get rid of the error "Cannot find 'ShareStore' in scope", try refreshing, cleaning and rebuilding your project/pods! It should be found.

carsten-klaffke avatar Jun 25 '24 08:06 carsten-klaffke

That made the trick! Thanks a lot for your support and quick responses.

markelarizaga avatar Jun 26 '24 23:06 markelarizaga

@markelarizaga what exactly did you do to fix this issue? I'm having the exact same problem

Bash4195 avatar Aug 22 '24 01:08 Bash4195

@markelarizaga what exactly did you do to fix this issue? I'm having the exact same problem

Hi, in my case I just followed @carsten-klaffke's advice:

try refreshing, cleaning and rebuilding your project/pods! It should be found.

This worked for me. Is your error the same as me? The code not being able to find ShareStore?

markelarizaga avatar Aug 25 '24 09:08 markelarizaga

Hey @markelarizaga thanks for replying.

I didn't really understand what "refreshing, cleaning and rebuilding your project/pods" meant, but I was able to figure it out through asking chatgpt.

I did end up getting it working and the above advice from @carsten-klaffke was part of the solution for me. I'm pretty unfamiliar with all this iOS stuff so I personally found the instructions hard to follow - had to ask chatgpt for help. I'm not exactly sure what else was causing problems for me, but one thing I know I missed in the instructions was setting the app group id on both the ShareExtension and the main app.

Since multiple people have run into this issue now, I think it would be worthwhile to add instructions on how to refresh/clean/rebuild the project/pods.

I guess the moral of this story is, when you get stuck, ask chatgpt.

Bash4195 avatar Aug 25 '24 17:08 Bash4195

I think this is more like a general problem with Xcode and Pods. It can happen at different occasions - or not. So instructions here in this repo are not easy to do and probably not the right place. But we have these issue discussions now, where one might find help, too. And I agree, ChatGPT is great.

carsten-klaffke avatar Aug 27 '24 06:08 carsten-klaffke