Launching Viber app via URL scheme on iOS

后端 未结 9 1184
野趣味
野趣味 2020-11-30 12:46

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:

相关标签:
9条回答
  • 2020-11-30 13:18

    For Swift, you can do like that :)

    let viberShareUrl = "viber://forward?text=\(shareUrl)"
    let url:NSURL =NSURL(string: viberShareUrl)!  
    UIApplication.sharedApplication().openURL(url)
    
    0 讨论(0)
  • 2020-11-30 13:19

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

    • 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)

    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

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

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

    0 讨论(0)
  • 2020-11-30 13:20

    This points to the contact page

    viber://contact?number=38095xxxxxxx

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

    0 讨论(0)
  • 2020-11-30 13:24

    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.

    Look at their answer:

    support@viber.com:

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


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

    Example:

    viber://forward?text=foo
    
    0 讨论(0)
  • 2020-11-30 13:29

    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
    }
    
    0 讨论(0)
  • 2020-11-30 13:37

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

    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.

    Tested this on 5.6 Viber. Also works from 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!

    0 讨论(0)
提交回复
热议问题