Receive URL in Ionic for ios

2019-03-10 21:21发布

问题:

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

回答1:

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>


回答2:

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



回答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



回答4:

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



回答5:

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



回答6:

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.