5

I want to open my public page in vk app (if it is installed). How can I manage to do that

Here's the same trick with facebook

- (IBAction)facebook:(id)sender{
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://profile/1425897281000202"]]){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/1425897281000202"]];
        NSURL *url = [NSURL URLWithString:@"fb://profile/1425897281000202"];
        [[UIApplication sharedApplication] openURL:url];
    }
    else {
        [[UIApplication sharedApplication]
         openURL:[NSURL URLWithString:@"https://www.facebook.com/GooodApps"]];
    }
}

Thanx!

CBroe
  • 91,630
  • 14
  • 92
  • 150
mumble57
  • 61
  • 1
  • 10

3 Answers3

10

This works for me in Swift:

let appURL = NSURL(string: "vk://vk.com/id\(user.vkID)")!
let safariURL = NSURL(string: "vk.com/id\(user.vkID)")!

if UIApplication.sharedApplication().canOpenURL(appURL){
    UIApplication.sharedApplication().openURL(appURL)
} else {
    UIApplication.sharedApplication().openURL(safariURL)
}
9

Hi it should help you :)

NSURL *url = [[NSURL alloc] initWithString:@"vk://vk.com/ХХХ"];
[[UIApplication sharedApplication] openURL:url];
Ned
  • 1,378
  • 16
  • 28
  • Do you know perhaps of a similar solution for the Android app ? – android developer Nov 23 '14 at 08:02
  • I can be wrong, but this URL schema should also work for android. – Ned Nov 23 '14 at 10:15
  • I tried. It didn't, even though the other social networks apps URIs are identical . :( I've made a post about it here: http://stackoverflow.com/q/27043676/878126 – android developer Nov 23 '14 at 10:16
  • Hmm... strange, Ok I can ask how my android friends implemented this, on the next week. – Ned Nov 23 '14 at 10:19
  • I wonder where they've found it. I don't speak Russian, and it's quite hard for me to search there for this information. Thank you. – android developer Nov 23 '14 at 10:22
  • I speak Russian, but it was difficult to find this URL schema even for me :D Sure, no problem) – Ned Nov 23 '14 at 10:36
  • 1
    Hi again, my android friend told me that he has exception using this URL schema, maybe android VK application doesn't support it(( but he give me this link https://github.com/VKCOM/vk-android-sdk, maybe it will help you. – Ned Nov 26 '14 at 13:48
  • They answered me, so I told them to put the answer on SO, so that I could thank them. Anyway, thank you for your help ! – android developer Nov 26 '14 at 15:18
0
let appURL = NSURL(string: "vk://vk.com/id1")!
let safariURL = NSURL(string: "vk.com/id1")!

if UIApplication.sharedApplication().openURL(appURL){
    UIApplication.sharedApplication().openURL(safariURL))
}
Laurel
  • 5,965
  • 14
  • 31
  • 57