如何使用tvOS打开另一个应用程序?

时间:2022-06-02 20:35:00

Does UIApplication:openURL work?

UIApplication:openURL有效吗?

NSString *iTunesLink = @"http://www.youtube.com/watch?v=TFFkK2SmPg4";
BOOL did = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];

This does nothing.

这没什么。

1 个解决方案

#1


10  

I assume you're wanting to test a Custom URL Scheme. You will want to use canOpenURL to see if the URL can be opened first. canOpenURL returns a BOOL value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL returns YES then you would continue to open the URL with openURL.

我假设您要测试自定义URL方案。您将需要使用canOpenURL来查看是否可以先打开URL。 canOpenURL返回一个BOOL值,指示URL的方案是否可以由设备上安装的某个应用程序处理。如果canOpenURL返回YES,那么您将继续使用openURL打开URL。

YouTube links open the YouTube app by default on iOS devices. This behavior is not yet testable on the new Apple TV as YouTube's app is not accessible in the tvOS beta.

YouTube链接默认在iOS设备上打开YouTube应用。此行为尚未在新的Apple TV上测试,因为YouTube的应用程序无法在tvOS测试版中访问。

Here's an example of how to use canOpenURL to see if Facebook is installed on an iOS device using its Cutsom URL Scheme:

以下是如何使用canOpenURL查看Facebook是否使用其Cutsom URL方案安装在iOS设备上的示例:

Obj-C:

OBJ-C:

// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/355356557838717"]];
}
else {
   // FB not installed
   // Do something else
}

Swift:

迅速:

// Check if FB app installed on device
if UIApplication.sharedApplication().canOpenURL(NSURL(string:"fb://")!) {
    UIApplication.sharedApplication().openURL(NSURL(string:"fb://profile/355356557838717")!)
}
else {
    // FB not installed
    // Do something else
} 

I'd anticipate that applications such as Facebook, and others, will implement their Custom URL Schemes in the same manner as their iOS counterparts.

我预计Facebook等应用程序将以与iOS对应方式相同的方式实现自定义URL方案。

#1


10  

I assume you're wanting to test a Custom URL Scheme. You will want to use canOpenURL to see if the URL can be opened first. canOpenURL returns a BOOL value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL returns YES then you would continue to open the URL with openURL.

我假设您要测试自定义URL方案。您将需要使用canOpenURL来查看是否可以先打开URL。 canOpenURL返回一个BOOL值,指示URL的方案是否可以由设备上安装的某个应用程序处理。如果canOpenURL返回YES,那么您将继续使用openURL打开URL。

YouTube links open the YouTube app by default on iOS devices. This behavior is not yet testable on the new Apple TV as YouTube's app is not accessible in the tvOS beta.

YouTube链接默认在iOS设备上打开YouTube应用。此行为尚未在新的Apple TV上测试,因为YouTube的应用程序无法在tvOS测试版中访问。

Here's an example of how to use canOpenURL to see if Facebook is installed on an iOS device using its Cutsom URL Scheme:

以下是如何使用canOpenURL查看Facebook是否使用其Cutsom URL方案安装在iOS设备上的示例:

Obj-C:

OBJ-C:

// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/355356557838717"]];
}
else {
   // FB not installed
   // Do something else
}

Swift:

迅速:

// Check if FB app installed on device
if UIApplication.sharedApplication().canOpenURL(NSURL(string:"fb://")!) {
    UIApplication.sharedApplication().openURL(NSURL(string:"fb://profile/355356557838717")!)
}
else {
    // FB not installed
    // Do something else
} 

I'd anticipate that applications such as Facebook, and others, will implement their Custom URL Schemes in the same manner as their iOS counterparts.

我预计Facebook等应用程序将以与iOS对应方式相同的方式实现自定义URL方案。