In my app, I have a button which, when pressed, lets you watch a youtube video (a movie trailer). Within the app, without launching safari. Below you can see a code snippet.
I believe the problem is that when webViewDidFinishLoad was triggered, the UIButton was not added to the view yet. I implemented a small delay to find the button after the callback is returned and it works for me on ios5 and ios6. drawback is that there is no guarantee the UIButton is ready to be found after the delay.
- (void)autoplay {
UIButton *b = [self findButtonInView:webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside]; }
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
[self performSelector:@selector(autoplay) withObject:nil afterDelay:0.3]; }
I had to use the url http://www.youtube.com/watch?v=videoid this is the only way it will work for me