Launch Youtube app with a video
I have an app with a UIButton, I wish, when I click t开发者_Go百科he button that the iPhone launches Youtube app with directly my video ready to start to play, I've tried this code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=xxx"]];
But it launches Safari in the video page. I'm trying my app on actual device.
Thanks
As others have mentioned, this should indeed open the YouTube App- if you're testing it on your actual device.
Be aware that if you're running it in the simulator, it will open in Safari instead, as the simulator does not have the YouTube app.
Your code should be working fine, unless you're passing a bad YouTube link.
Make sure your URL begins with "http://www.youtube.com". That's the signifier for [UIApplication sharedApplication] to open the YouTube App.
Also check out this page about iOS URL schemes, and YouTube in particular.
精彩评论