Samia
Samia

Reputation: 35

What should I add to the hyperlink?

If I got a URL which was youtube.com/watch?v=Hj57OP5C-ls .. what should I add in in the code?

- (IBAction)btnYoutube:(id)sender {

    NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:@"youtube://user/%@",@"toyotaleasing"]];
    NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.youtube.com/user/%@",@"toyotaleasing"]];

    if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
        // Can open the youtube app URL so launch the youTube app with this URL
        [[UIApplication sharedApplication] openURL:linkToAppURL];
    }
    else{
        // Can't open the youtube app URL so launch Safari instead
        [[UIApplication sharedApplication] openURL:linkToWebURL];
    }
}

Upvotes: 1

Views: 46

Answers (2)

Shehzad Ali
Shehzad Ali

Reputation: 1845

do this :-)

- (IBAction)btnYoutube:(id)sender { 

   NSURL *linkToAppURL = [NSURL URLWithString:@"youtube://watch?v=Hj57OP5C-ls"]; 
   NSURL *linkToWebURL = [NSURL URLWithString:@"https://www.youtube.com/watch?v=Hj57OP5C-ls"]; 

   if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) { 
        // Can open the youtube app URL so launch the youTube app with this URL 
        [[UIApplication sharedApplication] openURL:linkToAppURL]; 
    } else{ 
       // Can't open the youtube app URL so launch Safari instead 
        [[UIApplication sharedApplication] openURL:linkToWebURL]; 
   } 
}

Upvotes: 2

Manann Sseth
Manann Sseth

Reputation: 2745

Try this,

NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:@"youtube://video/%@",@"Hj57OP5C-ls"]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@",@"Hj57OP5C-ls"]]

Upvotes: 0

Related Questions