首页 文章

单击按钮[复制]打开已安装的应用程序

提问于
浏览
-1

这个问题在这里已有答案:

我的应用程序名为Labmed,其中会出现一个按钮以打开“LAB Befund”应用程序 . 如果已安装“LAB Befund”,请打开应用程序,而不是转到AppStore .

码:

NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setValue:ltvController forKey:@"LAB Befund"];
[array addObject:dic];

NSString *LABAppURL = "LAB Befund://openApp?param1=XXX&param2=YYY";
NSString *LABWebURL = @"https://itunes.apple.com/de/app/lab-befund/id1019115877?mt=8";


BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:LABWebURL]];


NSLog(@"can open: %d", canOpenURL);

NSString *url = canOpenURL ? LABAppURL : LABWebURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

这就是我到目前为止在互联网上找到的东西 . 它正在打开Appstore,因为安装了应用程序 .

我在我的.plist中添加了以下语句:

URL types
   Item0
      URL Schemes
         Item0
      URL Identifier

CanOpenURL返回“NO” .

CONCLUSION: 假设有两个应用程序TestA和TestB . TestB想要查询是否安装了TestA . “TestA”在其info.plist文件中定义了以下URL方案:

<key>CFBundleURLTypes</key>
<array>
<dict>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>testA</string>
    </array>
</dict>

第二个应用程序“TestB”试图通过调用以确定是否安装了“TestA”:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"TestA://"]];

但这通常会在iOS9中返回NO,因为需要将“TestA”添加到TestB的info.plist文件中的LSApplicationQueriesSchemes条目中 . 这是通过将以下代码添加到TestB的info.plist文件来完成的:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>TestA</string>
</array>

这就是它对我有用的方式 .

1 回答

  • 0

    您必须在 LABAppURL 中将 "LAB Befund" 替换为您已放入LAB Befund的Info.plist中的处理程序(URL Schema) .

相关问题