iOS開發 app版本更新, 提醒

來源:互聯網
上載者:User
/**
     *  檢測版本升級需要用到的參數
     */    iFeverAPPID = @"1076057848”; //appId; //調用檢測版本更新的方法     [selfcheckVersion];
*
 *  檢測軟體是否需要升級
 */
-(void)checkVersion
{
    //擷取當前應用版本號碼
    NSDictionary *appInfo = [[NSBundlemainBundle] infoDictionary];
    NSString *currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];
    //  用__block才能在局部範圍中改變變數的值
    __block NSString *newVersion = @"";
    NSString *updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%ld",(long)[iFeverAPPIDintegerValue]];
   
    NSString * str = [updateUrlStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
        NSLog(@"123 + %@", operation);
        NSDictionary *resultDic = responseObject;
        NSArray *resultArray = [resultDicobjectForKey:@"results"];
       
        for (idconfig in resultArray) {
            newVersion = [config valueForKey:@"version"];
        }
        if (newVersion) {
            NSLog(@"通過AppStore擷取的版本號碼是:%@", newVersion);
        }
       

result == 1

        NSComparisonResult result = [newVersion compare:currentVersion];
        if ( result == 1 ) { //appstore 版本大於目前的版本
            NSString *versionMessageStr = [ NSString stringWithFormat : @" 目前的版本 %@, 最新版本為 %@, 請升級 ." ,currentVersion,newVersion];
            UIAlertView *alert = [[ UIAlertView alloc ] initWithTitle : @" 升級提示 !" message : versionMessageStr delegate : self cancelButtonTitle : @" 下次再說 " otherButtonTitles : @" 現在升級 " , nil ];
            alert. tag = kVersionNeedUpdateAlertTag ;
            [alert show ];
        }
       
    } 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 = [ NSURL URLWithString :[ NSString stringWithFormat : @"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8" , iFeverAPPID ]];             [[UIApplicationsharedApplication]openURL:url];                     }
    } }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.