有没有办法让用户下载&在使用另一个应用程序时安装一个iOS应用程序,并在应用程序下载并可用时收到通知?
问题:
我有一个应用程序(说App1),我想检查是否有另一个应用程序(说App2)在设备中可用。如果App2不可用,我需要从itunes下载。一旦下载完成,我需要提醒用户App2下载已经完成,可以使用了。
我试着搜索iTunes API来做这个,但是我没有找到任何东西
唯一的解决方案是尝试从App1打开App2中指定的URL Scheme。并从App1连续轮询它,直到找到为止。
Objc
- (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];
}
}
迅速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()
}
}
}
这将告诉你你的应用程序在设备上是否可用。这是应用间通信,你可以在这里阅读更多内容