22

I am using ionic framework. I'm trying to set up a way to receive a url from another app. Like, you are in browser, click share, and send the link to another app (my app). I found this cordova plugin, and have integrated it in my app. But this is pulgin for Android. I need same functionality in IOS.

Any idea which plugin i need to use for ios

Steps taken by me for Android

1) cordova plugin add git://github.com/Initsogar/cordova-webintent.git 2) Checked config.xml file and found code for webintent

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

And app.js code

if (window.plugins && window.plugins.webintent) {
  window.plugins.webintent.getUri(function(url) {
    alert("getUri url:"+url);
  });
}

Any suggestions for the same functionally in ios ?

Thank you

Community
  • 1
  • 1
Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87
  • Hey @Hitu I am also looking for the same kind of functionality , have you got anything – user2028 Dec 27 '16 at 12:41
  • @Siddharth what kind of issue you are facing now ? – Hitu Bansal Dec 28 '16 at 09:57
  • @HituBansal did you ever end up figuring this out? The closest thing I've found was this http://engineering.curalate.com/2017/03/09/ios-share-ext-with-ionic.html but this is still hacky and doesn't sound like it will work that well. Then I found this which looks promising... https://github.com/j3k0/cordova-plugin-openwith – Ambrose Leung Feb 10 '18 at 07:49
  • Yes. i was able to fix that issue. – Hitu Bansal Feb 14 '18 at 04:58

6 Answers6

17

All you need is Custom-URL-scheme cordova plugin.

You can do it manually also. For iOS add to your *.plist. Or You can look at Step 5

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>URL_SCHEME</string>
    </array>
  </dict>
</array>

In iOS after adding custom scheme it automatically calls a function called handleOpenURL.

For android add AndroidManifest:(In android you can even listen http scheme)

<activity android:label="@string/app_name" android:name="com.yourpackage.name">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="example.com" android:pathPrefix="/" />
        <data android:scheme="https" android:host="example.com" android:pathPrefix="/" />
    </intent-filter>
</activity>
Kenster
  • 23,465
  • 21
  • 80
  • 106
engincancan
  • 2,442
  • 2
  • 28
  • 43
  • I have implemented the same. i am not able to see my appicon, when i click share button from Safari – Hitu Bansal Jun 04 '15 at 06:22
  • What do you mean about appicon? For example you have a scheme like `foo` if app is installed on iOS device you can call it like `href="foo://app/home"` and it should open your app if not you are doing something wrong – engincancan Jun 04 '15 at 06:29
  • No, i guess you understand my question wrong. i am reading an article in safari browser. i want to share that link(url) to myapp. when i click share from safari, i want to list my app – Hitu Bansal Jun 04 '15 at 06:31
  • URLs belonging to a given URL type are characterized by their scheme components, such as `http`, `ftp`, `mailto`, or `file`. The `CFBundleURLSchemes` key in the scheme-definition dictionary specifies an array of schemes that characterize URLs of this type. So try to add http scheme to your app and i guess you can see your icon. Source:https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html – engincancan Jun 04 '15 at 07:19
  • can u provide an example for the same. i have no idea about that – Hitu Bansal Jun 04 '15 at 07:21
  • Simply add one more URLscheme as http. It should do it – engincancan Jun 04 '15 at 08:37
  • I am little be confused now. Do you wanna open your app some click or else? Called deeplinking so you share somelink on social media platform and when clicked your app will open that way. But you are saying you want a option in safari share link. Then now AirDrop option which one is your purpose – engincancan Jun 05 '15 at 11:49
  • i am not sure you got my question or not. Let me explain you. I m on device and reading an article on Safari or chrome browser. I want to share an article with anyone. when i hit share, it is showing AirDrop in which some apps are there. I want to show myapp on Airdrop to. So user can able to share that article using my myapp. – Hitu Bansal Jun 05 '15 at 12:52
3

what you are asking is deep linking facility for your app. Although I can't provide you exact solution but its fairly simple by writing few lines of code into your native ios app's .plist file (just like what you did for android in manifest.xml). Its called URL scheming, and you can make one for your ios app too.

Please go to http://docs.urbanairship.com/topic-guides/ios-deep-linking.html. I hope it provides you guidance over how you can do this.

The angular/ionic code which opens 'another app that has provided deep linking facility(like youtube,etc.)' - https://medium.com/angularjs-articles/deep-linking-in-ionic-mobile-applications-44d8b4685bb3

Vineet 'DEVIN' Dev
  • 1,183
  • 1
  • 10
  • 35
3

What you are looking for is called Action Extension introduced in iOS 8. Your app will appear in standard acton/share sheet in all system and 3rd party apps and will be able to handle any kind of data, not just URLs.

App Extension Programming Guide from Apple

Tricertops
  • 8,492
  • 1
  • 39
  • 41
  • Yes, but i am not able to implement this. Could you please provide any example for the same – soccer7 Jun 15 '15 at 04:38
  • @iMartin I thought there is a difference between an Action extension and a Sharing extension. Action implies viewing/transforming, while sharing is different? – Eno Jun 17 '15 at 17:41
  • @Kamalpreet Because you are using some JavaScript wrapper? – Tricertops Jun 18 '15 at 17:14
  • @Eno You are right there are two kinds: _Share_ and _Action_ extension. _Share_ should send the content somewhere to the internet, while _Action_ is used for all other non-sharing services. From what I understood, OP want to process the URL in app, so I suggested _Action_. They are otherwise very similar in implementation and usage. – Tricertops Jun 18 '15 at 17:18
  • 1
    @Kamalpreet I never implemented one myself, but there is Xcode template to all kinds of extensions. It’s great place to start. – Tricertops Jun 18 '15 at 17:20
  • @iMartin: I am using ionic Framework. Guide is not helpful for me – soccer7 Jun 19 '15 at 07:19
  • @Kamalpreet You would have to implement an iOS sharing/action extension as a Cordova plugin to use it from Ionic. I dont think one exists right now. – Eno Jun 30 '15 at 20:43
1

Hope this vanger's post helps you.

In iOS to open any application you need to know which URLs schemes supported by this app.

For example, you can open email-writer by url like "mailto:aaa@bbb.com". But the thing is in application you can declare your own scheme. For example in App1 you can declare scheme like "my-app1-scheme". And in your second app you will need to open URL "my-app1-scheme://" and your App1 will be opened.

And I just found this plugin that allows you to do this in simpler way: https://github.com/EddyVerbruggen/Custom-URL-scheme

Community
  • 1
  • 1
soumya
  • 3,801
  • 9
  • 35
  • 69
0

There seems to be a plugin now iOS-Phonegap-app-share-extension. I didn't try it though.

Johnny Oin
  • 557
  • 5
  • 16
-1

On Android, you can use the WebIntent plugin to register your app as a receiver for the Share intent. Im not sure if a similar extension is available for iOS.

extempl
  • 2,987
  • 1
  • 26
  • 38
Eno
  • 10,730
  • 18
  • 53
  • 86
  • Yes, as I said above, Im not sure if something similar is available for iOS. I have also been using Ionic but Ive not (yet) found a Cordova plugin that hooks into the native sharing extensions and provides hooks into JavaScript. Am seriously considering writing my own. – Eno Jun 18 '15 at 22:29
  • Is this what you are looking for? https://www.npmjs.com/package/cordova-plugin-openwith-ios – Phantom007 Sep 24 '18 at 06:56