iOS APP如何實現版本檢測更新

2021-07-13 14:21:08 字數 2042 閱讀 4850

原理:拿到蘋果伺服器我們產品資訊(包含版本號version和buile 還有產品的所有資訊)跟當前安裝的產品的版本進行比較。

2、根據上面的位址請求需要的資訊

//檢測更新

/*responseobject是個字典{},有兩個key

*///具體實現為

nsarray *arr = [responseobject objectforkey:@"results"];

nsdictionary *dic = [arr firstobject];

nsstring *versionstr = [dic objectforkey:@"version"];

nsstring *trackviewurl = [dic objectforkey:@"trackviewurl"];

nsstring *releasenotes = [dic objectforkey:@"releasenotes"];//更新日誌

//nsstring* buile = [[nsbundle mainbundle] objectforinfodictionarykey: (nsstring*) kcfbundleversionkey];build號

nsstring* thisversion = [[nsbundle mainbundle] objectforinfodictionarykey:@"cfbundleshortversionstring"];

uialertcontroller *alertvc = [uialertcontroller alertcontrollerwithtitle:[nsstring stringwithformat:@"發現新版本:%@",versionstr] message:releasenotes preferredstyle:uialertcontrollerstylealert];

uialertaction *cancelaction = [uialertaction actionwithtitle:@"取消" style:uialertactionstylecancel handler:^(uialertaction * _nonnull action) ];

uialertaction *okaction = [uialertaction actionwithtitle:@"更新" style:uialertactionstyledefault handler:^(uialertaction * _nonnull action) ];

[alertvc addaction:cancelaction];

[alertvc addaction:okaction];

[self presentviewcontroller:alertvc animated:yes completion:nil];

}} failure:^(nsurlsessiondatatask * _nullable task, nserror * _nonnull error) ];

//比較版本的方法,在這裡我用的是version來比較的

bool littlesunresult = false;

while (a.count

< b.count)

while (b.count

< a.count)

for (int j = 0; j.count; j++) else

if([[a objectatindex:j] integervalue] < [[b objectatindex:j] integervalue])else

}return littlesunresult;//true就是有新版本,false就是沒有新版本

}

3、總結(注意點):1>我用的是afn 3.1.0版本(相容ip6)所以用的是afhttpsessionmanager物件; 2>uialertview棄用了,說實話我工程裡用的都是它,因為當時沒棄用。現在用的就是這個。見怪不怪,就是更好用了。

iOS App檢測版本更新

1 先介紹一下介面 返回資料 其中version是最新的版本號,releasenotes為新版本的更新內容 1 搜尋應用 2 右鍵單擊應用 2 實現 在 void 每次啟動應用的時候檢查更新 self 具體方法 void requesturl nsstring url cgsize size mes...

IOS APP如何實現公升級

當前執行程式的版本資訊,可以在 mainbundle 裡面獲取 cpp view plain copy print?nsdictionary infodict nsbundle mainbundle infodictionary nsstring currentversion infodict ob...

iOS App的版本檢測更新功能 最新版

今天是真正的想寫一篇部落格,以前都是工作忙沒時間,所以從來沒認真寫過,就從今天起吧 由於上傳突然斷網,博主又重新謝了一遍.下面是關於版本檢測更新的介紹 nsdictionary infodic nsbundle mainbundle infodictionary cfshow bridge cfty...