0

I know this question is answered for many same time of title or with different title.I am trying below code.

UIApplication.sharedApplication().openURL(videoURL) 

This line of code works fine in iOS simulator 8.xx/9.xx and returns true. But When I am trying to run my code in iPhone 9.Xx(unfortunately don't have iOS 8.xx device) then this line

UIApplication.sharedApplication().openURL(videoURL) 

is giving false.

I thought ,since my url contain https:// so i tried changing it to http:// but still no luck.Is there any kind of entry requires in .plist file somewhere.I assume but don't know if thats how it should be done.Can you guys help me out in this.

Regards

Manish Singh
  • 310
  • 1
  • 5
  • 19

3 Answers3

1

I used this code on actual device iPhone iOS 9.3.3

let videoURL = "https://www.youtube.com/watch?v=sFY-NDAAgFo"
UIApplication.sharedApplication().openURL(NSURL(string: videoURL)!)

It just opened safari with youtube video

For http we need to add a key in Info.plist nowadays since iOS 9

Just before your last dict write these lines in Info.plist viewed as Source code.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

enter image description here

Alternatively you can add a new key and make it as a dictionary and add a Boolean field as shown in image

Rajan Maheshwari
  • 14,465
  • 6
  • 64
  • 98
  • info.plist entry was already there in my project,And I have tried let videoURL = "https://www.youtube.com/watch?v=sFY-NDAAgFo" UIApplication.sharedApplication().openURL(NSURL(string: videoURL)!).still no luck UIApplication.sharedApplication().openURL(NSURL(string: videoURL)!) is still giving false.But on sim its working.Any way thanks for replying – Manish Singh Jul 28 '16 at 07:04
  • your url format is not fine.Just write `let videoURL = https://www.youtube.com/watch?v=sFY-NDAAgFo` – Rajan Maheshwari Jul 28 '16 at 07:06
  • And Info.plist is always there in every project. Whats new in that. I asked you to add Transport Security key. But that you will only be used if you are using http and not https – Rajan Maheshwari Jul 28 '16 at 07:08
  • Just copy paste the same URL codes that I have written in answer and check on device – Rajan Maheshwari Jul 28 '16 at 07:08
  • If it worked for you kindly tick as corrected as answer – Rajan Maheshwari Jul 28 '16 at 07:11
  • here is my observation ,I tried making one simple app and have run that on 9.3.2 and 9.0.1 ,Its working on 9.3.2 but not working on 9.0.1.Though i believe there are not much changes in these iOS version.But if any pls let me know. – Manish Singh Jul 28 '16 at 07:11
  • Currently I dont have any iOS 9.0.x version device or simulators. So I might not be the right person to answer that – Rajan Maheshwari Jul 28 '16 at 07:12
  • thats not an issue dude, Atleast i have something working and I will try to figure out what going on here.Btw thanks for your suggestions – Manish Singh Jul 28 '16 at 07:14
  • 1
    @ManishSingh I think this might help you http://apple.stackexchange.com/questions/231581/safari-on-ios-9-2-1-9-3-wont-open-links There are bugs in iOS 9.0.x version which apple has fixed them in later versions – Rajan Maheshwari Jul 28 '16 at 07:19
  • See this thread too https://discussions.apple.com/thread/7239092?tstart=0 – Rajan Maheshwari Jul 28 '16 at 07:20
  • good suggestion @Rajan ,Its an issue with 9.0.1 which got fixed with 9.3.x – Manish Singh Jul 28 '16 at 07:32
  • Googling always helps . – Rajan Maheshwari Jul 28 '16 at 07:37
0

remember this from iOS 9 onwards you can use SFSafariViewController

import SafariServices

private func openMYUrl(url: NSURL) {
        if #available(iOS 9.0, *) {
            let svc = SFSafariViewController(URL: url)
            svc.delegate = self
            self.presentViewController(svc, animated: true, completion: nil)
        }
        else {
            UIApplication.sharedApplication().openURL(url)
        }
    }

NOTE: if you are not using this app will reject . in my case its happen.

Ramkumar chintala
  • 958
  • 11
  • 24
  • No, its not like that. The sdks like google sign in make a reason for rejection. I just submitted the app last month which has a textview with links of youtube and many other google sites. Apple never rejected and accepted in first go. Depends what you are using. Generally the sdks nowadays use SafariController – Rajan Maheshwari Jul 28 '16 at 07:36
0

This is an apple bug for iOS 9.0.x which got fixed in iOS 9.3.x.I am pasting the link for someone who wants to refer this link for for more info.Thanks Rajan for your answer and suggestion

Please go through this apple release note

Manish Singh
  • 310
  • 1
  • 5
  • 19