EternallLight / cordova-plugin-openwith-ios

A modified version of the Cordova iOS Share extension (cordova-plugin-openwith) by Jean-Christophe Hoelt for iOS. Supports receiving shared URLs, text and images as well as sharing several images at once.
https://web-mystery.com/
MIT License
28 stars 84 forks source link

Sharing Error - You have to be logged in.... #3

Open kyleamadio opened 6 years ago

kyleamadio commented 6 years ago

The log seems to have all the expected data suggesting the plugin is correctly set up.

magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][onReset] magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][pluginInitialize] OK magicalCordovaIOS[4088:1574349] [CDVTimer][openwithplugin] 0.059009ms magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][onReset] magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][setVerbosity] 0 magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][setLogger] OpenWithPlugin72745820 magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][setHandler] OpenWithPlugin72745821 magicalCordovaIOS[4088:1574349] THREAD WARNING: ['OpenWithPlugin'] took '9233.975098' ms. Plugin should use a background thread. magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][init] magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][checkForFileToShare]

magicalCordovaIOS[4088:1574349] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x1d010c600> (Domain: group.com.CordovaIOS.magical.shareextension, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd

magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][checkForFileToShare] Nothing to share magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][setLoggedIn] 1 magicalCordovaIOS[4088:1574349] 03-05 21:58:30 D openwith: init() magicalCordovaIOS[4088:1574349] 03-05 21:58:45 D openwith: addHandler() magicalCordovaIOS[4088:1574349] 03-05 21:58:45 D openwith: initSuccess() magicalCordovaIOS[4088:1574349] init success! magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][onResume] magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][checkForFileToShare] magicalCordovaIOS[4088:1574349] [OpenWithPlugin.m][checkForFileToShare] Nothing to share

kyleamadio commented 6 years ago

The code is not setting or keeping a value for self.userDefaults for the key "loggedIn"

[self.userDefaults setBool:value forKey:@"loggedIn"];

kyleamadio commented 6 years ago

I hardcoded the value as true as isLoggedIn does not return as True

//BOOL isLoggedIn = [self.userDefaults boolForKey:@"loggedIn"];
BOOL isLoggedIn = true;
kyleamadio commented 6 years ago

Nothing is being shared:

[OpenWithPlugin.m][onResume] [OpenWithPlugin.m][checkForFileToShare] [OpenWithPlugin.m][checkForFileToShare] Nothing to share magicalCordovaIOS[4207:1610177] PBItemCollectionServicer connection disconnected.

viking2917 commented 6 years ago

I have pretty much the same behavior. Share opens up my app to receive the share but I get the same messages as @kyleamadio

kyleamadio commented 6 years ago

I had to move the Entitlement file. Check if it's has the App Groups in yours. If not look for another copy of the file as I had one at the root of the hierarchy and one in the Resource folder.

I now have sharing working on IOS. If you need more help contact me again and I'll share my set up.

viking2917 commented 6 years ago

@kyleamadio interesting... I have two entitlements files:

./platforms/ios/intentTest3/Entitlements-Release.plist
./platforms/ios/intentTest3/Entitlements-Debug.plist

And they are both essentially empty...and don't contain anything looking like the app group. e.g. the "release" one is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<plist version="1.0">
    <dict>
    </dict>
</plist>

Any further details/suggestions much appreciated!

kyleamadio commented 6 years ago

These are the two Entitlement files. They are additional to the DEBUG and Release files

screen shot 2018-03-19 at 7 53 10 pm
kyleamadio commented 6 years ago

Here they are in Xcode

screen shot 2018-03-19 at 7 58 56 pm
viking2917 commented 6 years ago

@kyleamadio Awesome! Thank you for this. I manually edited the entitlements files and it appears to be working now, at least in the simulator. Odd that the plugin didn't update those entitlements automatically. The original plugin this is forked from (https://github.com/j3k0/cordova-plugin-openwith) makes a cryptic comment about entitlements ("Build, XCode might complain about a few things to setup that it will fix for you (creation entitlements files, etc)."), and I did experience Xcode offering to fix some things but not until after I made your edits to the entitlements files. Still, it seems to be working, at least on a test app! It doesn't seem to be working yet in an installed app on a physical device but I am sure that is my mistake and I'll sort that out I expect. Thank you so much for the help!

viking2917 commented 6 years ago

I am able to get this working on a sample app when run from Xcode. however when I run it from the Ionic command line, it doesn't work - it gets the same "nothing to share" message. I'm guessing somehow ionic isn't putting the entitlements onto the device, or isn't building the share extension target or something. Continuing to investigate but any insight appreciated!

kyleamadio commented 6 years ago

@viking2917 I don’t use Ionic, just straight Cordova (hard core, hehehe). Any way I used Xcode to figure out the issue as the command line was not helping... and then I build via the command line.

viking2917 commented 6 years ago

:) My only real worry about the command line not working, is if the problem might resurface when I release a production app; hopefully that process will work. I'll post an update when I strike bottom on it. Thanks so much for the help!

kyleamadio commented 6 years ago

Fairly sure it will be ok. You can test that by running the app on the device from the command line too.

cordova run ios

viking2917 commented 6 years ago

that's my point - when I do that (except I do 'ionic cordova run ios'), the sharing doesn't work. but it does when I run from Xcode.

kyleamadio commented 6 years ago

You may need to copy those entitlements files to another location for the command line to see them.

viking2917 commented 6 years ago

Could you tell me where yours are? I've tried in a few different places and it doesn't seem to help....e.g. what does this say in your project?

find . -name '*.entitlements' -print

kyleamadio commented 6 years ago

OK I'll check shortly, out and about

kyleamadio commented 6 years ago

./platforms/ios/ShareExt.entitlements ./platforms/ios/magicalCordovaIOS/Resources/magicalCordovaIOS.entitlements ./platforms/ios/magicalCordovaIOS/magicalCordovaIOS.entitlements

screen shot 2018-03-21 at 1 04 37 pm
kyleamadio commented 6 years ago

I just tested using "cordova run ios" and the sharing did not work. Run via Xcode did work. I guess the placement of the entitlement files may be affecting the CLI method of running the app

kyleamadio commented 6 years ago

I tried placing the files in a few locations could not get it to work via the CLI - only via XCode

viking2917 commented 6 years ago

wow @kyleamadio thank you for the extra effort. I also spent most of the day banging my head against this, including redoing all the app provisioning and certs and such in hopes of fixing it (it did not). I also noticed that this plugin creates a target with a different Deployment Target than the base app (my test app was using 11.0/Universal whereas the share extension was 9.0/iPhone. While fixing this did not solve the problem of CLI not working, I do wonder if the share extension will work correctly on iPad unless one changes these to match....

In the meantime, it sounds like your production app works just fine. I'm OK if I can't test Share in the CLI, so long as it works in production - it sounds like your app works fine in prod.

Again thanks for all the work. If I can return the favor let me know....I'm pondering merging the code here with the Ionic Native web intent plugin (https://ionicframework.com/docs/native/web-intent/) which only supports only Android. If I can get this working prod-wise, and if I'm successful merging these two apps, it'd be nice to have a single plugin handling "Share" for iOS/Android in a single API. I'll post back here if I do that.

kyleamadio commented 6 years ago

would be happy to test. Production = running via Xcode, its not approved by Apple yet - That is the next hurdle....

viking2917 commented 6 years ago

good luck! :)

anthonnyc2 commented 5 years ago

Hi guys, I hope your things going well. I'm getting that message ("You have to be logged in...."), even after hardcoded to be always true in the OpenWithPlugin.m - (void) setLoggedIn:(CDVInvokedUrlCommand*)command { // BOOL value = [command argumentAtIndex:0]; BOOL value = true; [self.userDefaults setBool:value forKey:@"loggedIn"]; [self.userDefaults synchronize]; [self debug:[NSString stringWithFormat:@"[setLoggedIn] %d", value]]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } I not sure what can I do to avoid that validation. Any suggestion?

viking2917 commented 5 years ago

@anthonnyc2 did to do the steps mentioned above related to the entitlements file? (and also see the note above about xCode offering to "fix" things for you, did you get that?). Also in Xcode, do you have two build targets? (one for your app, one for the share extension?), and do they have the same build target?

Also for some period of time I could not get sharing to work when I ran from the command line but could when running from Xcode. I fixed that eventually but don't remember what it was I did that fixed it...

In Xcode, under Capabilities, do you have both build targets assigned to the same App Group?

In Xcode, I had to manually add the cocoapods lib, libPods-Bookship.a, under the share extension build target's build phases rule

and I'm fairly sure I had to add/remove the ios platform once or twice, (and then make sure to redo the xcode changes).

Sorry - shooting in the dark here, these are just some things I stumbled over.

Flucadetena commented 5 years ago

Hi, hope someone can help me. I'm getting the Error:

The entitlements specified in your application’s Code Signing Entitlements file are invalid, not permitted, or do not match those specified in your provisioning profile. (0xE8008016).

I've manage to track it down to one thing, every time I add the group.<YOUR_APP_BUNDLE_ID>.shareextension to my app (not to the extension), that happens. If I simply don't added, and just leave it in the extension target, everything loads perfectly. When I do this, I get the app to apear in the share menu and to open the app when trying to share something (after setting the 'LoggedIn value to true' as mentioned before).

But for what I can see, when the app starts, it is not executing the 'init(), handler()' functions or any other. So when I share some 'URL', nothing happens, it just opens the app.

If tried everything for hours, and it only happens when I add the group.

Hope someone can help, really need this to work. Thanks!

viking2917 commented 5 years ago

I don't have any real insight into your error, but since it mentions the code signing entitlements, I would double check your developer.apple.com app ID setup, make sure your you have app groups enabled on your main app ID. I also have a separate app id for my extension but honestly I can't remember if I needed that, or just created it when I was trying to get all this working.

From the installation docs, I would double check the below:

When a user posts some content using the Share Extension, the content will be stored in a Shared User-Preferences Container. To enable this, the Cordova App and Share Extension should define a group and add both the app and extension to it, manually. At the moment, it seems like it's not possible to automate the process. You can read more about this here.
Flucadetena commented 5 years ago

Hi Viking, if check my App Id tons of times, and already have two app Ids, one fro the app and the other one for the extension. In both the app groups are enable. And the problem is exactly where you are pointing me to double check.

When I add the group to the main app, xcode doesn't give me any errors but when I build I get the entitlements error.

Thanks for the quick response.

benjdg16 commented 5 years ago

Do you guys have any workaround on this?

I have setup the App groups on both targets. The ShareViewController.h is also configured correctly. I have also used the init and addHandler functions.

When I run this using cordova run ios --target='iPhone-X' (on XCode 9) or cordova run ios --target='iPhone-X' --buildFlag='-UseModernBuildSystem=0' (on XCode 10) my application is displayed inside the sharelist, however it does nothing and there is no intent received (init success is logged on console). Meanwhile, when I try running this on XCode it does not show my application inside the sharelist.

Any comment/suggestion is much appreciated, thanks!

viking2917 commented 5 years ago

@benja3 so, i went back and looked at my notes for what I did for iOS, and I am seeing that in fact I had to slightly modify this plugin to get it work for me, because I could never get the "logged in" state to register correctly. I think - but am not sure - that I was seeing the same symptom as you. It's been quite some time since I set this up. My app (which is in production and sharing of text between apps works) uses my own fork of this repo. You are welcome to try it out: https://github.com/viking2917/cordova-plugin-openwith-ios.

Caveat: I am an idiot about this stuff, I just hacked til it worked. Buyer beware :)

https://github.com/viking2917/cordova-plugin-openwith-ios

viking2917 commented 5 years ago

also @benja3 per notes above in this thread, I don't think I ever got sharing to work when running the app from the ionic CLI. I had to run from inside xCode.

benjdg16 commented 5 years ago

Hello guys,

I have managed to make this work, for iOS 11.1 at least. For iOS 12.0 I am having some issues sharing images.

I've used automatic signing for ShareExt target and that made it work for me. Also my product identifier for ShareExt was wrong, sorry about that (it should have .shareextension at its end, my bad).

@viking2917 Thanks for the quick response, I'll take a look into this :)

benjdg16 commented 5 years ago

@viking2917 In addition to this, did you manage to share images for iOS 12?

viking2917 commented 5 years ago

@benja3 My use case doesn't involve sharing images, sorry :(

benjdg16 commented 5 years ago

@viking2917 Thanks for the reponse :)

Sorry if my other question does not fall inside this thread, thanks guys!

viking2917 commented 5 years ago

for posterity and my own personal memory: I again started having trouble getting the sharing to "trigger". I discovered that the entitlements files don't seem to get uniformly updated with the keys: So: APPNAME/platforms/ios/Bookship/Entitlements-Debug.plist contained:

<key>com.apple.security.application-groups</key>
 <array>
    <string>group.com.ionicframework.<myappname>.shareextension</string>
 </array>

whereas platforms/ios/Bookship/Entitlements-Release.plist did not. If I ran in my Debug Scheme/Build, sharing worked. If I ran in "Release" mode it did not work.

So I manually edited the Release plist file to include the above, rebuilt and sharing started working again in the "Release" build".

Adding/removing the plugin does not seem to address this issue, I think there's something not-quite-right in the plugin code that alters the plist file, but I can't quite figure it out.