iOS開發 app版本更新, 提醒

/**

*檢測版本升級需要用到的參數

*/

iFeverAPPID=@"1076057848”; //appId;

//調用檢測版本更新的方法

[selfcheckVersion];

*

*檢測軟件是否需要升級

*/

-(void)checkVersion

{

//獲取當前應用版本號

NSDictionary*appInfo = [[NSBundlemainBundle]infoDictionary];

NSString*currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];

//用__block才能在局部作用域中改變變量的值

__blockNSString*newVersion =@"";

NSString*updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPIDintegerValue]];

NSString* str = [updateUrlStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

AFHTTPRequestOperationManager*manager = [AFHTTPRequestOperationManagermanager];

[managerGET:strparameters:nilsuccess:^(AFHTTPRequestOperation*operation,idresponseObject) {

NSLog(@"123 + %@", operation);

NSDictionary*resultDic = responseObject;

NSArray*resultArray = [resultDicobjectForKey:@"results"];

for(idconfiginresultArray) {

newVersion = [configvalueForKey:@"version"];

}

if(newVersion) {

NSLog(@"通過AppStore獲取的版本號是:%@", newVersion);

}

result ==1

NSComparisonResultresult = [newVersioncompare:currentVersion];

if(result == 1) { //appstore 版本大于當前版本

NSString*versionMessageStr = [NSStringstringWithFormat:@"當前版本%@,最新版本為%@,請升級.",currentVersion,newVersion];

UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"升級提示!"message: versionMessageStrdelegate:selfcancelButtonTitle:@"下次再說"otherButtonTitles:@"現在升級",nil];

alert.tag=kVersionNeedUpdateAlertTag;

[alertshow];

}

}failure:^(AFHTTPRequestOperation*operation,NSError*error) {

NSLog(@"234 + %@", error);

}];

}

#pragma mark - UIAlertDelegate Method

//收到推送時程序正在前臺運行,則給出一個alert,用戶選擇查看,執行這個方法,并且跳轉到指定頁面

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if(buttonIndex ==1) {

//軟件需要更新提醒

if(alertView.tag==kVersionNeedUpdateAlertTag) {

NSURL*url = [NSURLURLWithString:[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8",iFeverAPPID]];

[[UIApplicationsharedApplication]openURL:url];

}

}

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容