在 iOS 上通过 URL 方案启动 Viber 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30541805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:07:52  来源:igfitidea点击:

Launching Viber app via URL scheme on iOS

iosurl-schemeviber

提问by Scofield Tran

I'm making an iOS app which can open Viber app and automatically call a person or go to chat window with the person. Is there any url scheme for Viber to do that such as:

我正在制作一个 iOS 应用程序,它可以打开 Viber 应用程序并自动呼叫某人或与该人进入聊天窗口。Viber 是否有任何 url 方案可以做到这一点,例如:

viber://tel:<phone_number>
viber://chat:<phone_number>

I followed thislink but it's for Android.

我点击了这个链接,但它适用于Android。

回答by Oleh Melnyk

as for now (26.03.2017), I found this URI are working:

至于现在 (26.03.2017),我发现这个 URI 正在工作:

  • viber://add?number=NUMBER - open user page
  • viber://forward?text=foo - share text with selected users
  • viber://chats - opens chat tab
  • viber://calls - opens calls tab
  • ??? - can't find how to open user's/contacts tab
  • viber://public - opens a public tab
  • viber://more - open more tab (the last one in the row)
  • viber://add?number=NUMBER - 打开用户页面
  • viber://forward?text=foo - 与选定的用户共享文本
  • viber://chats - 打开聊天标签
  • viber://calls - 打开通话选项卡
  • ???- 找不到如何打开用户/联系人选项卡
  • viber://public - 打开一个公共标签
  • viber://more - 打开更多选项卡(行中的最后一个)

and some links to interact with Public Accounts https://developers.viber.com/tools/deep-links/index.html- viber://pa?chatURI=hello&context=abcdefg&text=hi - attempt to wrte hi to hello public account

以及一些与公共帐户交互的链接 https://developers.viber.com/tools/deep-links/index.html- viber://pa?chatURI=hello&context=abcdefg&text=hi - 尝试向 hello 公共帐户写信

support forum: https://support.viber.com/

支持论坛:https: //support.viber.com/

and they have chrome extension - https://support.viber.com/customer/en/portal/articles/2191386-new-chrome-web-extension#top

他们有 chrome 扩展 - https://support.viber.com/customer/en/portal/articles/2191386-new-chrome-web-extension#top

回答by andreacipriani

I sent a mail to the Viber support and they told me that this kind of URL (opening Viber call/chat with a phone number) are no more supported. When typing Viber version is 5.6.

我向 Viber 支持人员发送了一封邮件,他们告诉我不再支持这种 URL(打开 Viber 呼叫/使用电话号码聊天)。打字时 Viber 版本是 5.6。

Look at their answer:

看看他们的回答:

[email protected]:

[email protected]:

"Thank you for contacting us. Unfortunately, there isn't such option in Viber."

“感谢您联系我们。很遗憾,Viber 中没有这样的选项。”



The only thing I've found is an url to forward a message: https://www.viber.com/en/developers/share_on_viberyou can specify the text but not the recipient

我发现的唯一一件事是转发消息的网址:https: //www.viber.com/en/developers/share_on_viber您可以指定文本但不能指定收件人

Example:

例子:

viber://forward?text=foo

回答by Yarik

I've found one way to "almost" call using Viber - by adding contact:

我找到了一种使用 Viber“几乎”呼叫的方法 - 通过添加联系人:

viber://add?number=0123456789

This will open Viber "Add Contact" dialog, and user can finally call expected number after adding it as a new contact.

这将打开 Viber“添加联系人”对话框,用户可以在将其添加为新联系人后最终拨打预期号码。

Tested this on 5.6 Viber. Also works from HTML:

在 5.6 Viber 上对此进行了测试。也适用于 HTML:

<a href="viber://add?number=%2B49150123456789">Viber me</a>

However, if contact doesn't exist, the first click would only open the Dialog, save new contact and go back to your application/page. Clicking the same link again will open directly contact view with Call out button

但是,如果联系人不存在,则第一次单击只会打开对话框,保存新联系人并返回到您的应用程序/页面。再次单击相同的链接将直接打开带有呼出按钮的联系人视图

Cheers!

干杯!

回答by iamomkaar

viber://contact?number= mobile number

It will open the particular user contact. Give user to select chat and call.
it worked for me!

它将打开特定的用户联系人。让用户选择聊天和通话。
它对我有用!

回答by Juan Catalan

You could use this code to accomplish what you want:

您可以使用此代码来完成您想要的:

NSString *phoneNumber = @"1112223333";
NSString * const viberScheme = @"viber://";
NSString * const tel = @"tel";
NSString * const chat = @"chat";
NSString *action = @"<user selection, chat or tel>"; // this could be @"chat" or @"tel" depending on the choice of the user

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:viberScheme]]) {

    // viber is installed
    NSString *myString;
    if ([action isEqualToString:tel]) {
        myString = [NSString stringWithFormat:@"%@:%@", tel, phoneNumber];
    } else if ([action isEqualToString:chat]) {
        myString = [NSString stringWithFormat:@"%@:%@", chat, phoneNumber];
    }

    NSURL *myUrl = [NSURL URLWithString:[viberScheme stringByAppendingString:myString]];

    if ([[UIApplication sharedApplication] canOpenURL:myUrl]) {
        [[UIApplication sharedApplication] openURL:myUrl];
    } else {
        // wrong parameters
    }

} else {
    // viber is not installed
}

回答by Александр Бабич

This points to the contact page

这指向联系页面

viber://contact?number=38095xxxxxxx

viber://contact?number=38095xxxxxxx

IMPORTANT: Don't put + at the beginning of the number, it won't work otherwise

重要提示:不要将 + 放在数字的开头,否则将不起作用

回答by user4981345

This works: "viber://chats" or "viber://calls"

这有效:“viber://chats”或“viber://calls”

回答by wailynnzaw

For Swift, you can do like that :)

对于 Swift,你可以这样做:)

let viberShareUrl = "viber://forward?text=\(shareUrl)"
let url:NSURL =NSURL(string: viberShareUrl)!  
UIApplication.sharedApplication().openURL(url)

回答by Ankur Gupta

You can check by using

您可以使用

[[UIApplication sharedApplication] canOpenURL:@"viber://url"];

if Viber app is installed on device, and viber handle this url scheme it will return true otherwise false.

如果设备上安装了 Viber 应用程序,并且 viber 处理此 url 方案,它将返回 true,否则返回 false。