Unable to open YouTube URL to be played on YouTube tvOS Application - swift

Question:
How do I open a YouTube URL (from my tvOS Application) to the YouTube tvOS Application?
Description:
My url fits the youtube url scheme indicated by apple. The prints I get when I run this (on the actual apple tv device) is as follows:
"Can open shared application url."
"tvOS 10.0 detected"
"Result... false"
So for some reason it's telling me that I'm able to open the url, but then when I attempt to open it. Nothing happens (except for that last print ( see 3. above ))
let url = URL(string: "https://www.youtube.com/watch?v=smOp5aK-_h0")
if UIApplication.shared.canOpenURL(url){
print("Can open shared application url.")
if #available(tvOS 10.0, *) {
print("tvOS 10.0 detected")
UIApplication.shared.open(url){res in
print("Result..." + String(res))
}
} else {
// Fallback on earlier versions
UIApplication.shared.openURL(url)
}
}
Youtube URL Scheme:
Native app URL strings:
http://www.youtube.com/watch?v=VIDEO_IDENTIFIER
http://www.youtube.com/v/VIDEO_IDENTIFIER

Many tvOS devs would like to have an option to play YouTube content in their apps on the AppleTV, which is only possible through the YouTube app. It's up to Google to add support for URL schemes compatible with the ones available in the iOS version of the app and they don't seem motivated to make this extra effort.

While the methods do exist to open a URL in a shared application, it does not seem to be supported (by YouTube?) as of right now.
The best I was able to do was to open YouTube Apple Tv App, but it is unable to play the video I wanted.

Related

How to get the list of applications suitable for routing from the user’s device?

Is there any way to check if user has a certain app (google.maps, yandex.maps or native maps) on his/her device to make a list of apps suitable for routing?
You can check if user has this apps on device (google.maps, yandex.maps or native maps) using URL scheme.
for Google maps:
let appURL = URL(string: “comgooglemaps://”)
if UIApplication.shared.canOpenURL(appURL!) {
// code for open URL
print(“Can Open URL”)
}

How to launch Health iOS app from another iOS APP

I am trying to launch Health app from my application.
I usually try with the following lines of code for launching application like as
let mystr = "health://"
let myurl = NSURL(string: mystr)!
if (UIApplication.sharedApplication().canOpenURL(myurl))
{
UIApplication.sharedApplication().openURL(myurl)
}
else
{
print("unable to open")
}
I tried above code.i am getting error ("null").
Some one please help in this issue.
Thanks in advance.
With iOS 10+ try this:
let mystr = "x-apple-health://"
Maybe in objective.c:
-(IBAction)openAppHealth:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"x-apple-health://"] options:#{} completionHandler:nil];
}
with new openURL for iOS 10
openURL: deprecated in iOS 10
You cannot open HealthApp directly from your app. Because OS is supporting only for opening the settings App using UIApplicationOpenSettingsURLString. If we use URL scheme to open the HealthApp, then Apple may reject the App in review process.
I don't have any experience with the HealthKit framework but here's what I found :
According to Open Apple Health programmatically you cannot create a deeplink from your app to the Health app because it is not supported.
If you'd wish to use the Health app's data you'll have to implement the HealthKit framework into your app and asks for permission to your users.
I tried to deeplink into the Health app using code that works for other apps and got the same results as you.

Opening Facebook event pages in the Facebook app using Swift

I am having a problem getting Facebook events in the Facebook app. For example, to open an event with the url "https://www.facebook.com/events/1743847059178738/," I would use the following code:
let facebookURL = NSURL(string: "fb://event/1743847059178738")!
if UIApplication.sharedApplication().canOpenURL(facebookURL) {
UIApplication.sharedApplication().openURL(facebookURL)
} else {
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.facebook.com/events/1743847059178738")!)
}
}
It will open the Facebook app, but no matter what event I attempt to display I get a screen saying "Unable to load event. It may have been cancelled." I have tried substituting the Facebook URL of an event for that of a profile (e.g., string: "fb://profile/100005906912309") and it works just fine. Am I mistaken in assuming that the numbers at the end of the event's URL are the same as the event's numeric ID?
So I figured out that I could bypass the whole "fb://event..." bit and just go with:
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.facebook.com/events/1743847059178738")!)
I assumed this would open the link in Safari, but it automatically opened in Facebook in iOS 8.
I'm sorry for the late answer. I'd prefer to write this as comment, but I'm not able to.
First, nice work around. I think it is a perfect fallback if the fb:// scheme fails as it shown in code shared with your question. I've spent a lot of time trying to resolve the same issue. What I've found is that fb://event/{event-id} is no longer supported and it was replaced with fb://event?id={event-id}.
I've used this post as a reference.

Default FBSDKLoginBehavior.Native not working on iOS 9

I just upgraded my app to Xcode 7 / Swift 2.0 and I'm struggling with the Facebook Login via AppSwitch. I'm on the latest FBSDK (4.6) and did everything according to the upgrade guide. Still, on iOS9 the Facebook login happens via in-app browser, the appswitch doesn't work anymore. I also tried force setting the loginbehavior but without luck:
let manager = FBSDKLoginManager()
manager.loginBehavior = FBSDKLoginBehavior.Native
manager.logInWithReadPermissions(facebookReadPermissions, fromViewController: nil, handler: { (loginResult, error) -> Void in
Is there anything I can do to make appswitch work again?
Thanks!
Turns out that this is not an issue but the new desired behavior according to these posts from Facebook:
https://developers.facebook.com/bugs/1636969533209725/?comment_id=1011596265571252
This behavior is by design. In our latest iOS SDKs, the login behavior is now controlled on the server side in order to ensure the best user experience.
https://developers.facebook.com/bugs/786729821439894/?comment_id=1467419033584031
Because of introduced changes in iOS 9, This new behavior avoids the user to be asked if they want to go and open the Facebook Application, accept the permissions/share/etc, and then ask once more if they want to switch back to your app.
https://developers.facebook.com/bugs/1390559277910338/?comment_id=1661064587442645
System authentication doesn't give people control over the information they share with apps. And in iOS 9, fast-app-switching to the Facebook native app results in additional dialogs ("ExampleApp would like to open Facebook") which appear twice - once on the way from ExampleApp to Facebook, and once again on the return journey. We believe the default SDK behavior in v4.6 on iOS 9 offers the best experience to people logging into your app with Facebook.
You can patch FacebookSDK source code to use Fast App Switching.
The interesting part (for tag 4.6) is in file FBSDKCoreKit/Internal/ServerConfiguration/FBSDKServerConfigurationManager.m
+ (FBSDKServerConfiguration *)_defaultServerConfigurationForAppID:(NSString *)appID
{
…
BOOL useNativeFlow = ![FBSDKInternalUtility isOSRunTimeVersionAtLeast:iOS9Version];
As you can see, it disables native flow on iOS9+.
Changing the line to something like BOOL useNativeFlow = YES; should work.
P.S. I didn't check this patch myself yet.

Ajax call to check if native iPhone application exists on the device?

For our iPhone native application we have a URL : example://
On the iPhone if I type this URL (example://) in safari it automatically opens up my application.
From my "regular" website I have a link which when the user clicks it opens the application. The problem is that if the application is not installed on the iPhone it throws "Unable to open" error.
So before rendering the link on my "regular" site I need to check if the app is installed, one solution is to make an Ajax call and check for status code:
$.ajax({
type: 'POST',
url: 'example://',
complete: function (transport) {
if (transport.status == 200) {
alert('Success');
} else {
alert(transport.status);
alert('Failed');
}
}
});
But this code is always returning a status code "0".
Is there a way to find out from the web if the native iPhone app is installed?
If u are referring to Mobile Safari, you're out of luck. There's no documented public API that I know of that can do this. Mobile Safari is sandboxed away from the OS.
If it's in a webview within an app, u can request the URL and let the webview delegate talk to the native app / query the handling of example://. Otherwise, no way the browser can know existence of any installed app.