强制用户在iOS中通过编程方式更新应用程序

9
在我的iOS应用程序中,我已经启用了强制应用程序更新功能。它是这样的。
如果有关键错误修复,在服务器上设置新的发布版本。在闪屏界面中,我检查当前应用程序版本,如果低于服务版本,则显示更新应用程序的消息。
我放置了两个按钮“立即更新”和“稍后更新”。
我有两个问题:
1. 如果我现在点击。应用程序应该打开我的应用程序商店,并显示UPDATE按钮。目前我使用链接"http://appstore.com/mycompanynamepvtltd",这会打开我的公司应用程序列表,但即使我的应用程序有新的更新,它也只有OPEN按钮而没有UPDATE按钮。应该去哪个URL才能进入更新页面?
2. 如果他点击“稍后更新”按钮,关闭应用程序是否可以?这会导致我的应用程序被拒绝吗?
请帮我解答这两个问题。

1
在我看来,一个关闭应用程序的按钮并不是真正的“稍后”。如果我点击“稍后”,我希望应用程序能继续运行。 - Paulw11
如果用户没有安装强制更新版本,我想停止让他使用应用程序。最好的做法是什么?@Paulw11 - user1960169
不要通过编程方式关闭应用程序。苹果可能会拒绝该应用程序。我曾经遇到过这种情况。更好的方法是不允许用户使用该应用程序。保留更新按钮。用户要么前往应用商店,要么自己关闭应用程序。 - Amit
@Amit 谢谢,你知道我应该使用什么链接去我的应用商店吗? - user1960169
1
请查看此论坛:https://forums.developer.apple.com/thread/52767。很多人都遇到了这个问题。在我的项目中,我将用户重定向到我们的网站页面,从App Store下载应用程序。这样,如果用户在应用商店中没有更新按钮,至少可以在Safari中使用网站。 - Amit
这可以帮助您完成您的目的。如果您想强制用户升级,则每次都会显示弹出窗口。https://github.com/emotality/ATAppUpdater - Pankaj K.
5个回答

7

第二点:如果您不希望用户稍后更新,则应仅将强制更新作为选项允许。程序化关闭应用程序不是正确的选择。

第一点:您可以使用可用于此目的的优秀库。

在Swift中的用法:

func applicationDidBecomeActive(application: UIApplication) {
    /* Perform daily (.daily) or weekly (.weekly) checks for new version of your app.
    Useful if user returns to your app from the background after extended period of time.
     Place in applicationDidBecomeActive(_:)*/

    Siren.shared.checkVersion(checkType: .daily)
}

Objective-C中的使用方法:

-(void)applicationDidBecomeActive:(UIApplication *)application {
    // Perform daily check for new version of your app
    [[Harpy sharedInstance] checkVersionDaily];
}

它是如何工作的:它使用查找API返回应用程序详细信息,例如链接,包括版本,并进行比较。
例如,通过调用https://itunes.apple.com/lookup?id=284910350来按iTunes ID查找Yelp软件应用程序。
有关更多信息,请访问链接

1
这个代码如何检查我的应用版本并将用户重定向到更新页面? - user1960169

4
请勿编程自动关闭应用程序,否则苹果公司可能会拒绝该应用程序。更好的方法是不允许用户使用该应用程序,保留更新按钮,以便用户前往应用商店或自己关闭该应用程序。
根据苹果公司的规定,应用程序不应该在自身未被打开时就终止运行。因为用户没有按Home键,任何返回到主屏幕都会让用户误以为应用程序崩溃了。这种行为令人困惑,非标准化,应该避免。
请查看此论坛:https://forums.developer.apple.com/thread/52767。这种情况发生在很多人身上。在我的项目中,我将用户重定向到我们网站上的应用程序下载页面。这样,如果用户在应用商店中找不到更新按钮,至少用户可以在Safari中使用网站。

2

回答你的问题:

  1. 使用以下链接直接打开你的应用程序商店页面:https://apps.apple.com/app/id##########,其中##########是你的应用程序的10位数字ID。你可以在App Store Connect的“应用信息”部分找到该ID。它被称为“Apple ID”。
  2. 我实际上在我的应用程序中建立了终止功能,如果它过时了,并且不能再对从服务器接收到的数据进行操作(我的应用程序是一款需要连接到我的Web服务的信息应用程序)。虽然这个功能从未被启用过,但我的应用程序在几年内进行了十几次更新后仍未因此功能而被拒绝。为了避免未来的更新被拒绝,我将切换到静态消息,而不是终止应用程序。

我发现审核过程至少在某种程度上是主观的,不同的审阅者可能会专注于不同的事情,并因为之前被忽略多次的内容而予以拒绝。


1
func appUpdateAvailable() -> (Bool,String?) {
    
    guard let info = Bundle.main.infoDictionary,
          let identifier = info["CFBundleIdentifier"] as? String else {
        return (false,nil)
    }
    
    //        let storeInfoURL: String = "http://itunes.apple.com/lookupbundleId=\(identifier)&country=IN"
    let storeInfoURL:String = "https://itunes.apple.com/IN/lookup?bundleId=\(identifier)"
    var upgradeAvailable = false
    var versionAvailable = ""
    
    // Get the main bundle of the app so that we can determine the app's version number
    let bundle = Bundle.main
    if let infoDictionary = bundle.infoDictionary {
        // The URL for this app on the iTunes store uses the Apple ID for the  This never changes, so it is a constant
        let urlOnAppStore = NSURL(string: storeInfoURL)
        if let dataInJSON = NSData(contentsOf: urlOnAppStore! as URL) {
            // Try to deserialize the JSON that we got
            if let dict: NSDictionary = try?
                JSONSerialization.jsonObject(with: dataInJSON as Data, options: JSONSerialization.ReadingOptions.allowFragments) as! [String: AnyObject] as NSDictionary? {
                if let results:NSArray = dict["results"] as? NSArray {
                    let versionDict = NSMutableDictionary(dictionary: results[0] as! [String:Any])
                    
                    if let version = versionDict.object(forKey: "version") as? String {
                        
                        // Get the version number of the current version installed on device
                        if let currentVersion = infoDictionary["CFBundleShortVersionString"] as? String {
                            // Check if they are the same. If not, an upgrade is available.
                            print("\(version)")
                            print("\(currentVersion)")

                            if version != currentVersion {
                                upgradeAvailable = true
                                versionAvailable = version
                            }
                        }
                    }
                }
            }
        }
    }
    return (upgradeAvailable,versionAvailable)
}

func checkAppVersion(controller: UIViewController){
    
    let appVersion = appUpdateAvailable()
    
    if appVersion.0 {
        alertController(controller: controller, title: "New Update", message: "New version \(appVersion.1 ?? "") is available")
    }
}


func  alertController(controller:UIViewController,title: String,message: String){
    let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
    alertController.addAction(UIAlertAction(title: "Update", style: .default, handler: { alert in
                    
        //itms-apps://itunes.apple.com/app/ewap/id1536714073
        guard let url = URL(string: "https://apps.apple.com/us/app/cdoc-see-your-doctor-anytime/id1133534055") else { return }
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        } else {
            UIApplication.shared.openURL(url)
        }
    }))
    DispatchQueue.main.async {
        controller.present(alertController, animated: true)
    }
    
}

0
使用appgrades.io。让第三方解决方案发挥作用,让您的应用程序专注于提供业务价值。通过appgrades,一旦集成SDK,您可以创建自定义视图/警报,显示给旧版本用户,要求他们更新其应用程序。您可以自定义限制视图/警报中的所有内容,使其看起来像是您应用程序的一部分。

1
注意:这是一项付费服务。 - thomers

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接