Launching Viber app via URL scheme on iOS

后端 未结 9 1231
野趣味
野趣味 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: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 = @""; // 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
    }
    

提交回复
热议问题