Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以编程方式检测iPhone上是否安装了应用程序_Iphone_Url_Installed Applications - Fatal编程技术网

以编程方式检测iPhone上是否安装了应用程序

以编程方式检测iPhone上是否安装了应用程序,iphone,url,installed-applications,Iphone,Url,Installed Applications,在这种情况下,我必须在iphone应用程序中显示一个按钮,上面写着“打开myApp”(如果设备上安装了myApp),或者写着“下载myApp”(如果设备上没有安装myApp)。为此,我需要检测设备上是否安装了应用程序(具有已知的自定义URL)。我该怎么做?提前感谢。更新了2014年1月8日-您可以做的三件事 事实上,我不得不再次为一位客户这样做。他们希望用户能够从主应用程序(如果已安装)打开第二个应用程序 这是我的发现。使用canOpenURL方法检查是否安装了应用程序,或者/然后使用openU

在这种情况下,我必须在iphone应用程序中显示一个按钮,上面写着“打开myApp”(如果设备上安装了myApp),或者写着“下载myApp”(如果设备上没有安装myApp)。为此,我需要检测设备上是否安装了应用程序(具有已知的自定义URL)。我该怎么做?提前感谢。

更新了2014年1月8日-您可以做的三件事

事实上,我不得不再次为一位客户这样做。他们希望用户能够从主应用程序(如果已安装)打开第二个应用程序

这是我的发现。使用
canOpenURL
方法检查是否安装了应用程序,或者/然后使用
openURL
方法

  • 打开安装在iOS设备上的应用程序
  • 将用户直接带到应用商店,将其指向应用/您的开发者应用列表
  • 把他们带到网站上去
  • 每个场景可用的所有代码示例

    //Find out if the application has been installed on the iOS device
    - (BOOL)isMyAppInstalled { 
        return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"nameOfMyApp:"]]; 
    } 
    
    - (IBAction)openOrDownloadApp { 
        //This will return true if the app is installed on the iOS device
        if ([self myAppIsInstalled]){
            //Opens the application
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"nameOfMyApp:"]]; 
        } 
        else { //App is not installed so do one of following:
    
            //1. Take the user to the apple store so they can download the app
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/nameOfMyApp"]]; 
    
            //OR
    
            //2. Take the user to a list of applications from a developer
            //or company exclude all punctuation and space characters. 
            //for example 'Pavan's Apps'
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/PavansApps"]];
    
            //OR
    
            //3. Take your users to a website instead, with maybe instructions/information
             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.pavan.com/WhyTheHellDidTheAppNotOpen_what_now.html"]];
    
        } 
    }
    
    选择一个选项,我已经用选择宠坏了你。选择一个适合你的要求。
    在我的例子中,我必须在程序的不同区域使用这三个选项。

    如果你的应用程序的URL方案是“myapp:”,那么


    (需要iOS 3.0。)

    您可以在任何需要此应用程序嗅探的页面头部添加一个简单的元标记

    有关更多信息,请访问此处:


    检查应用程序是否安装在设备中

    1) 在info.plist中添加LSApplicationQueriesSchemes,如下例所示

    2) 和URL类型

    3) 现在检查应用程序是否已安装

    - (IBAction)openAppPressed:(UIButton *)sender {
        NSString *urlString = @"XYZAPP://";
        NSURL *url = [NSURL URLWithString:urlString];
    
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }
        else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itunes link for download app"]];
        }
    }
    

    对于那些使用canOpenURL的用户来说,从这个迁移到
    openURL:options:completionHandler:

    NSString *urlString = @"XYZAPP://";
    NSURL *url = [NSURL URLWithString:urlString];
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
            if (!success) {
                [[UIApplication sharedApplication] openURL:appStoreUrl options:@{} completionHandler:nil];
            }
    }];
    
    因为这不需要你提前申报计划


    canOpenURL
    已经有了一些奇怪的限制,因为Twitter很久以前就用它来检测数百个应用程序。

    iOS 4中找不到plist。你知道它搬到哪里去了吗?嗨,很抱歉回复晚了。没问题。该文件位于“/private/var/mobile/Library/Caches/”文件夹中。希望有帮助。Cheers这是交换机案例2中的路径。但是找不到该文件(在iOS 4.3上)。。。我还在4.2.1版上,山姆叹了口气,如果有什么东西很快升级到4.3版,我会做一些研究,然后帮你找到它。当我这样做的时候,你将是我第一个联系的人。Android有没有类似的方法?也许,在你的帖子中总结你的URL的内容会比仅仅发布一个链接更能帮助用户。除此之外,在你的第一篇帖子上做得很好:-)。@bkbeachlabs比什么简单多了?我一定是指另一个答案的早期编辑。很久以前了,现在我不记得了!
    NSString *urlString = @"XYZAPP://";
    NSURL *url = [NSURL URLWithString:urlString];
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
            if (!success) {
                [[UIApplication sharedApplication] openURL:appStoreUrl options:@{} completionHandler:nil];
            }
    }];