简体   繁体   English

通过iOS和Android中的URL方案打开Snapchat和Instagram

[英]Open Snapchat and Instagram via URL Scheme in iOS and Android

I thought it was as simple as using a URL scheme such as snapchat:// or instagram:// but I have tried this and nothing happens (in iOS or Android). 我以为它就像使用url://或instagram://这样的URL方案一样简单,但是我已经尝试过了,但没有任何反应(在iOS或Android中)。

I'm trying to achieve this within a Cordova app. 我正在尝试在Cordova应用程序中实现这一目标。 Ideally I'd like to launch Snapchat or Instagram and load a video in or open the 'browse gallery' page, but if that isn't possible I'd settle with just being able to open the apps themselves. 理想情况下,我想启动Snapchat或Instagram并在其中加载视频或打开“浏览图库”页面,但是如果不可能的话,我将能够自己打开应用程序。

Two thoughts: 两个想法:

  1. If you already have the InAppBrowser plugin (cordova-plugin-inappbrowser) in your project, try calling window.open("snapchat://", "_system") (as per https://stackoverflow.com/a/17887465/2543147 this opens the browser app) which may then bounce the request onto the Snapchat app 如果您的项目中已经有InAppBrowser插件(cordova-plugin-inappbrowser),请尝试调用window.open("snapchat://", "_system") (按照https://stackoverflow.com/a/17887465/ 2543147,这将打开浏览器应用程序),然后可以将请求退回至Snapchat应用程序
  2. If that doesn't work, a plugin such as https://www.npmjs.com/package/cordova-plugin-app-launcher should allow you to do this easily. 如果这不起作用,则https://www.npmjs.com/package/cordova-plugin-app-launcher之类的插件应该可以使您轻松完成此操作。

This should work for iOS. 应该适用于iOS。 UIApplication.shared().openURL(URL("snapchat://"))

For Android, its convenient to do the following. 对于Android,方便地执行以下操作。

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (launchIntent != null) { 
    startActivity(launchIntent);//null pointer check in case package name was not found
}

I also recommend referring to the following site for more information on instagram -> http://www.gotschemes.com/search/?app_id=5268 我还建议参考以下网站,以获取有关instagram的更多信息-> http://www.gotschemes.com/search/?app_id=5268

Your problem most likely stems for how this looks in cordova and how thats translates to the underlying native sdk, since otherwise you're right this is typically very straightforward and easy to do. 您的问题很可能源于科尔多瓦的外观以及将其转换为基础本机sdk的原因,因为否则您是对的,这通常非常简单易行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM