如何通过空中传送更新ios6企业应用程序



您好,我们最近开发了第一个企业应用程序。我们正在使用"内部"选项来创建分发证书。客户端尚未使用该应用程序。但他很快就会使用它。与此同时,我有一个问题。他将使用该应用程序,将来如果我们对该应用程序有任何更新,我们希望客户也能对其进行更新。就像现在我的iPhone上安装了一些应用程序。我从应用商店得到更新,说XYZ应用程序已经更新。所以我安装了更新。现在,如果我们的客户端正在使用该应用程序并在其上保存了一些数据(我们的应用程序使用核心数据,我们以客户端可以在设备上存储一些数据的方式构建它),我们希望向他发送一个更新,安装更新,但不删除任何现有的客户端数据。这可能吗?我该怎么做?我现在正在使用无线安装来安装该应用程序。我们有一个安全的服务器,其中有.ipa和.plist文件,我们还有一个下载html页面。客户端点击链接,应用程序就安装好了。如果你需要更多信息,请告诉我。谢谢

是的,这是可能的。部署企业应用程序时,它需要一个包含应用程序元数据的plist。此元数据包括可用于检查更新的版本号。

BOOL updateAvailable = NO;
NSDictionary *updateDictionary = [NSDictionary dictionaryWithContentsOfURL:
[NSURL URLWithString:@"http://www.example.com/pathToPlist"]];
if(updateDictionary)
{
NSArray *items = [updateDictionary objectForKey:@"items"];
NSDictionary *itemDict = [items lastObject];
NSDictionary *metaData = [itemDict objectForKey:@"metadata"];
NSString *newversion = [metaData valueForKey:@"bundle-version"];
NSString *currentversion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
updateAvailable = [newversion compare:currentversion options:NSNumericSearch] == NSOrderedDescending;
}

一旦您检测到更新可用,请将用户导航到下载URL

itms-services://?action=download-manifest&url=<url-path-to-plist>

,它将在现有版本上安装,保留所有数据,如果您设置了自动迁移并进行更改,甚至可以升级CoreData数据库。

感谢Joe的精彩回应。这是翻译成swift的扩展版本。你可以把它放在主视图控制器的viewDidLoad里面

let plistUrl = "https://example.com/example.plist"
let installationUrl = "itms-services://?action=download-manifest&amp;url=https://example.com/example.plist"

override func viewDidLoad() {
super.viewDidLoad()
//Check for the updates        
checkForUpdates()
}
func checkForUpdates() {
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
let updateDictionary = NSDictionary(contentsOfURL: NSURL(string: self.plistUrl)!)!
let items = updateDictionary["items"]
let itemDict = items?.lastObject as! NSDictionary
let metaData = itemDict["metadata"] as! NSDictionary
let serverVersion = metaData["bundle-version"] as! String
let localVersion = NSBundle.mainBundle().infoDictionary!["CFBundleVersion"] as! String
let updateAvailable = serverVersion.compare(localVersion, options: .NumericSearch) == .OrderedDescending;
if updateAvailable {
self.showUpdateDialog(serverVersion)
}
})
}
func showUpdateDialog(serverVersion: String) {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let alertController = UIAlertController(title: "New version of Example available!", message:
"Example (serverVersion) has been released. Would you like to download it now?", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Not now", style: .Cancel,handler: nil))
alertController.addAction(UIAlertAction(title: "Update", style: .Default, handler: { (UIAlertAction) in
UIApplication.sharedApplication().openURL(NSURL(string: self.installationUrl)!)
}))
self.presentViewController(alertController, animated: true, completion: nil)
})
}

只需像分发原始更新一样分发更新即可。用户保留早期版本的数据。

@Vlad在swift 4 中的更新答案

var plistUrl = "https://xxxxxxxxxxxxxxfgfgf/ex.plist"
var installationUrl = URL(string : "itms-services://?action=download-manifest&url=https://xxxxxxxxxxxxxxfgfgf/ex.plist")

func checkForUpdates() {
let qos = DispatchQoS(qosClass: .background, relativePriority: 0)
let backgroundQueue = DispatchQueue.global(qos: qos.qosClass)
backgroundQueue.async(execute: {
let updateDictionary = NSDictionary(contentsOf: NSURL(string: self.plistUrl)! as URL)!
let items = updateDictionary["items"]
let itemDict = (items as AnyObject).lastObject as! NSDictionary
let metaData = itemDict["metadata"] as! NSDictionary
let serverVersion = metaData["bundle-version"] as! String
print ("serverVersion=",serverVersion)
let localVersion = Bundle.main.infoDictionary!["CFBundleVersion"] as! String
print ("localVersion=",localVersion)
let updateAvailable = serverVersion.compare(localVersion, options: .numeric) == .orderedDescending
print("version is newer")
if updateAvailable {
self.showUpdateDialog(serverVersion: serverVersion)
}
})
}
func showUpdateDialog(serverVersion: String) {
DispatchQueue.main.async { () -> Void in
let alertController = UIAlertController(title: "New version of  App  available!", message:
"MCD (serverVersion) has been released. Would you like to download it now?", preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "Not now", style: .cancel,handler: nil))
alertController.addAction(UIAlertAction(title: "Update", style: .default, handler: { (UIAlertAction) in
UIApplication.shared.open(self.installationUrl!, options: [:], completionHandler: nil)
}))
self.present(alertController, animated: true, completion: nil)
}}

但这只是一次,每次都需要更多的修改

对于应用程序更新,如果应用程序的捆绑包ID保持不变,则现有的应用程序数据将持续存在。

苹果在这里解释企业应用程序部署和应用程序更新:http://help.apple.com/iosdeployment-apps/mac/1.1/#app43ad802c

我还建议在应用程序中包含一个更新检查器。

为了做到这一点,iVersion是尼克·洛克伍德(又名木炭设计)的一个ios库,它将帮助你做到这一步。可在此处获取:https://github.com/nicklockwood/iVersion

最新更新