ios - 下载 iOS 应用程序并在下载完成后收到通知

标签 ios objective-c swift

有没有办法允许用户在使用另一个应用程序的同时下载和安装一个 iOS 应用程序,并在该应用程序下载并可用后收到通知?

问题:

我有一个应用程序(比如 App1),我想检查设备中是否有另一个应用程序(比如 App2)。如果 App2 不可用,我需要从 iTunes 下载。下载完成后,我需要提醒用户 App2 下载已完成并可以使用。

我试图搜索一个 iTunes API 来执行此操作,但我没有找到任何东西。

最佳答案

唯一的解决方案是尝试从 App1 打开 App2 中指定的 URL Scheme。并从 App1 不断地轮询直到找到它。

对象

- (void)checkForSiblingApp {
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"<app2scheme>://"]]) {

        //App exists! Show user a message and then call this to open the app
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"<app2scheme>://"]];
    } else {

        //App does not exist, check again in 1 minute
        [self performSelector:@selector(checkForSiblingApp) withObject:nil afterDelay:60];
    }
}

swift

func checkForSiblingApp() {

    if UIApplication.sharedApplication().canOpenURL(NSURL(string: "<app2scheme>://")!) {

        //App exists! Show user a message and then call this to open the app
        UIApplication.sharedApplication().openURL(NSURL(string: "<app2scheme>://")!)
    } else {

        //App does not exist, check again in 1 minute
        let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(60 * Double(NSEC_PER_SEC)))

        dispatch_after(delayTime, dispatch_get_main_queue()) {
            self.checkForSiblingApp()
        }
    }
}

这会告诉您您的应用程序在设备上是否可用。这是应用间通信,您可以阅读更多 here .

关于ios - 下载 iOS 应用程序并在下载完成后收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31320237/

相关文章:

ios - Swift 中 '_ in print()' 是什么意思?

iOS 7 UITabBar 角标(Badge)位置

iphone - iPhone 应用程序发布配置中的无尽 "for"循环

objective-c - UIScrollView 中的 iOS UIWebView

ios - 按下按钮时如何在 UITableviewCell 中显示自定义 View ?

objective-c - 开发像 Facebook 新 iOS 应用程序中的侧滑菜单的最佳方法是什么?

ios - 检测触摸是否在 Sprite 边界内,但忽略 child

ios - 在后台线程上加载 SpriteKit 场景会导致应用程序因内存问题而崩溃

xcode - 如何安装仅由 swift 文件组成的 swift 库

ios - 使用类中的项目填充 UIPickerView