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

How to install on capacitor? #93

Open
kalepail opened this issue Feb 7, 2020 · 8 comments
Open

How to install on capacitor? #93

kalepail opened this issue Feb 7, 2020 · 8 comments

Comments

@kalepail
Copy link

kalepail commented Feb 7, 2020

Capacitor doesn't support Cordova hooks so a walk through for how to get this plugin working on a Capacitor project would be amazing. Thanks! Excited to use this plugin.

@stevenleija
Copy link

Yes this would be great

@oudj001
Copy link

oudj001 commented Apr 23, 2020

Yeah, for me the same. Anyone already got this working? I tried to manually add the share extension and move the .m and .h files into the application. Also tried this tutorial: https://medium.com/@abhishekthaplithapliyal/ios-share-extension-930ba1ad3c3d , but i'm stuck with the process of getting the data in my app. It's stored in the NSUserDefaults in iOS..

Anyone?

@joshoconnor89
Copy link

I need help here as well. Im able to get it working with cordova but not capacitor :(

@ghost
Copy link

ghost commented Sep 9, 2020

I could use some help as well, thanks!

@ghost
Copy link

ghost commented Sep 18, 2020

Hi all, I was able to get this to work for Capacitor in iOS but it does require some modifications.
First I used the tutorial on https://medium.com/@abhishekthapliyal/ios-share-extension-930ba1ad3c3d to create a Share Extension for my app. Make sure that you pick Objective C as the language of the Share Extension and not Swift. This is important for the following steps. Add an App Group to your share extension and add the same App Group to your main application.
Now install this plugin. When you try to build your iOS project after the plugin is installed, you wel get a build error saying that ShareViewController.h can not be found when importing that in OpenWithPlugin.m. Now comes the part where you have to modify OpenWithPlugin.m (I know, not ideal). Remove the import of the file that can't be found. There is 1 reference in the OpenWithPlugin.m to a variable coming from that import. That reference is SHAREEXT_GROUP_IDENTIFIER. Replace this reference with the App Group id you added before. You can also replace it with a reference to your build setting if your app group id is different for your builds, that is up to you. That is it for OpenWithPlugin.m.
The plugin ships with a ShareViewController.h and ShareViewController.m files. You can find these in the node_modules folder of your Capacitor project in the folder of this plugin. Within that folder, both files are located at src/ios/ShareExtension. Copy both files to your Share Extension. In the extension should already be 2 files with the same name. Just overwrite those with the copied files. The .h files contains references to variables. Update those as follows: SHAREEXT_GROUP_IDENTIFIER is again the App group id you created earlier. SHAREEXT_URL_SCHEME is the custom URL scheme for opening your main app. Make sure you add this scheme as a URL Type in iOS and an intent in Android. The last one SHAREEXT_UNIFORM_TYPE_IDENTIFIER is the kind of files you are allowing (https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1).
When all the above is set, the shared files are handled in your app as described in this plugin by adding a handler to the openwith plugin and sharing should work in iOS as well.

I hope this helps.

@Saqib92
Copy link

Saqib92 commented Aug 21, 2021

any update?

@Saqib92
Copy link

Saqib92 commented Aug 21, 2021

Somehow I managed to make it work on Capacitor 3.

npm i cc.fovea.cordova.openwith
install via NPM

inside AndroidMenifest.xml
Menifest Settings

`<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.SEND_MULTIPLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>`

inside app.component.ts

declare var cordova;` // declare at top after imports

this.platform.ready().then(() => {
  this.setupOpenwith();
});

setupOpenwith() {
    cordova.openwith.init(initSuccess, initError);

    function initSuccess() { console.log('init success!'); }
    function initError(err) { console.log('init failed: ' + err); }

    // Define your file handler
    cordova.openwith.addHandler(myHandler);

    function myHandler(intent) {
      console.log('intent received');

      console.log('  action: ' + intent.action); // type of action requested by the user
      console.log('  exit: ' + intent.exit); // if true, you should exit the app after processing

      for (var i = 0; i < intent.items.length; ++i) {
        var item = intent.items[i];
        console.log('  type: ', item.type);   // mime type
        console.log('  uri:  ', item.uri);     // uri to the file, probably NOT a web uri

        // some optional additional info
        console.log('  text: ', item.text);   // text to share alongside the item, iOS only
        console.log('  name: ', item.name);   // suggested name of the image, iOS 11+ only
        console.log('  utis: ', item.utis);
        console.log('  path: ', item.path);   // path on the device, generally undefined
      }

      // ...
      // Here, you probably want to do something useful with the data
      // ...
      // An example...

      if (intent.items.length > 0) {
        cordova.openwith.load(intent.items[0], function (data, item) {

          // data is a long base64 string with the content of the file
          console.log("the item weights " + data.length + " bytes");


          // "exit" when done.
          // Note that there is no need to wait for the upload to finish,
          // the app can continue while in background.
          if (intent.exit) { cordova.openwith.exit(); }
        });
      }
      else {
        if (intent.exit) { cordova.openwith.exit(); }
      }
    }
  }  

@Saqib92
Copy link

Saqib92 commented Sep 23, 2021

This Plugin is only works for Capacitor Android. and had issues with IOS.
I used Below Mentioned plugin to make this feature in my app:
https://github.com/carsten-klaffke/send-intent

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

5 participants