ios - launch youtube channel in youtube app -
for launching video on youtube app, using below code.
nsurl *instagramurl = [nsurl urlwithstring:@"youtube://foo"]; if ([[uiapplication sharedapplication] canopenurl:instagramurl]) { nslog(@"opening youtube app..."); nsstring *stringurl = @"http://www.youtube.com/watch?v=h9vdapqywfg"; nsurl *url = [nsurl urlwithstring:stringurl]; [[uiapplication sharedapplication] openurl:url]; } else { // open in uiwebview in webviewviewcontroller webviewviewcontroller *secondview = [self.storyboard instantiateviewcontrollerwithidentifier:@"webinterface"]; secondview.headerlabel = @"youtube"; secondview.webpath = @"http://www.youtube.com/watch?v=h9vdapqywfg"; [self.navigationcontroller pushviewcontroller:secondview animated:yes]; }
now client changed mind , asking put channel in iphone app.
for testing, used link http://www.youtube.com/user/richarddawkinsdotnet
but when use link, instead of youtube app, opens in safari. :(
any idea/ suggestion on how can open channel in youtube app link provided?
you're code's going wrong because, although you're checking if can open youtube url more or less correctly, you're opening web address, open in safari.
this code i've used, working me. might want modify else statement if want fallback using webviewcontroller open safari if youtube app isn't installed.
nsstring *channelname = @"thenameofthechannel"; nsurl *linktoappurl = [nsurl urlwithstring:[nsstring stringwithformat:@"youtube://user/%@",channelname]]; nsurl *linktoweburl = [nsurl urlwithstring:[nsstring stringwithformat:@"http://www.youtube.com/user/%@",channelname]]; if ([[uiapplication sharedapplication] canopenurl:linktoappurl]) { // can open youtube app url launch youtube app url [[uiapplication sharedapplication] openurl:linktoappurl]; } else{ // can't open youtube app url launch safari instead [[uiapplication sharedapplication] openurl:linktoweburl]; }
Comments
Post a Comment