2

I have an iOS 9 only app which I am developing with a UITableViewController and a list of videos by a company. Some of the videos are hosted on YouTube. In the didSelectRowAtIndexPath, I implement the use of SFSafariViewController in the following way:

SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.youtube.com/watch?v=YQHsXMglC9A"]entersReaderIfAvailable:NO];
safariVC.delegate = self;
[self presentViewController:safariVC animated:YES completion:nil];

Please note, the video in that link is not the video I am using for my app - it's simply an example.

When I click that without the YouTube.app installed on my device, it opens up in SFSafariViewController. If I have YouTube.app installed, it prompts me to open the link in there:

enter image description here

I understand why this is happening, because of the work in iOS 9, but how can I prevent it? It'll be pretty annoying for my users to have to go to YouTube to watch the video and then come back to the app (even if it's via the back link at the top).

How can I prevent this from happening within the app, to say use the SFSafariViewController within the app rather than the YouTube app?

Update

This behaviour does not happen with the Twitter or Facebook native apps, so the question is, is this a YouTube native app issue (something I can't do anything about) or is there a way for me to prevent the opening? With SFSafariViewController, Apple's aim would have been to make it easier; there must be a way to prevent apps from prompting and loading in the native app.

Any guidance on this would be appreciated.

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

1 Answers1

1

I don't see a delegate to do this. I guess this is the native behavior and exactly what you get with a SFSafariViewController. You COULD recreate a 'light version' by using a WebView directly instead

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Thanks @daij - that's a real shame. I have UIWebView working with this and it doesn't call out to the YouTube app with it installed, but SFSafariViewController is so much nicer but this one thing is preventing me using it because a lot of people will have the YouTube app installed. Should I file some sort of radar with Apple regarding this? There should really be a control mechanism to prevent the opening of other apps from within the app. – amitsbajaj Dec 08 '15 at 15:35
  • Upon further investigation, I can see that this behaviour doesn't happen with the Facebook or Twitter app (I have the native of both). This link talks about the behaviour and that it shouldn't actually be doing what I'm experiencing in the question: http://stackoverflow.com/questions/32375916/safari-web-view-opening-when-logging-to-fb-through-ios-9 - Unless of course it's dependent on the app itself and perhaps the YouTube . App has not been updated with this in mind? Is there any way to force that it doesn't open, or prompt to open in the YouTube app? – amitsbajaj Dec 08 '15 at 15:56
  • Hi @Daij-Djan - did you have any further thoughts on this? – amitsbajaj Dec 09 '15 at 09:24
  • well I don't think the two apps are using SFSafariViewController – Daij-Djan Dec 09 '15 at 09:26
  • Thanks - while that is true that they don't use SFSafariViewController, unfortunately, neither is YouTube. So is there absolutely no way to prevent my app from opening in a third-party app? – amitsbajaj Dec 09 '15 at 14:54
  • besides not using it in your app -- no. Feel free to file a bug with apple if you need it – Daij-Djan Dec 09 '15 at 15:07