2016-10-10 88 views
0

我正在開發IOS應用程序。我有一個使用案例,我們必須強制用戶進行升級。例如,用戶可能位於版本1和另外兩個版本2和3(目前存在於應用商店中)。現在我們確定版本1存在安全漏洞,因此我們打開一個警報,要求用戶通過應用商店升級。我的做法,現在是如下: -根據最低版本標準爲IOS應用程序實施強制更新

1. Implement a rest service which vends the minimum required version. 
2. Implement a local upgrade handler that calls the rest service, 
    gets the current version(natively) and compares the version 
    against the min required version. 
3. If the version is lower than min required version, upgrade by 
    opening app store. 

到目前爲止,我已經能夠成功地實現了REST服務和升級處理程序的一部分。我的警報視圖代碼看起來如下所示: -

private func alertUserWithHandler(title: String?, message: String, upgradeHandler: ((UIAlertAction) -> Void)?){ 
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert) 
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: upgradeHandler)) 
    self.presentViewController(alert, animated: true, completion: nil) 
    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate)) 
} 

而且我升級處理器看起來爲如下: -

// The upgrade handler takes the user to the AppStore. 
func upgradeHandler(action:UIAlertAction) { 
    UIApplication.sharedApplication().openURL(NSURL(string:"location in appstore")) 
} 

這種方法的問題是它不是一個阻塞處理程序。用戶可以按確定按鈕,然後去應用程序商店,然後回來繼續使用該應用程序。我們要強制升級(即用戶在升級成功完成之前不能使用該應用程序)。

任何人都可以提出一個強制用戶升級的好方法嗎?

+0

你可以在沒有按鈕的'upgradeHandler()'中顯示另一個AlertController。 – FelixSFD

+0

@FelixSFD - 好的,但我怎麼會傳遞一個處理程序? –

+0

您可以在應用啓動時發送帶有用戶驗證請求的應用版本。所以在後端,如果版本太舊,它會返回一個錯誤。在應用程序中,你需要單獨處理這個錯誤。 – MaksTheAwesome

回答

1

我在Singleton類中創建了一個sharedInstance(),該類使用版本和構建參數訪問Web服務。如果它恢復正常,我會在應用程序中以模態方式呈現一個視圖,直到該Web服務返回false時才能解除該視圖。通過將其放入sharedInstance中,我不必在每個視圖控制器上調用它。當應用程序最初啓動時,我也會打電話給它。