筆記1客戶端應用程序更新版本

-(void)updataVersion
{  
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/javascript"];
    [manager GET:APP_URL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"AFHTTPRequestOperationJSON: %@", responseObject);
//        NSDictionary* resultDic=[responseObject.responseData JSONValue];
        NSArray* infoArray = [responseObject objectForKey:@"results"];
        if (infoArray.count>0) {
            NSDictionary* releaseInfo =[infoArray objectAtIndex:0];
            NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];
            NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
            NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
            if (![appStoreVersion isEqualToString:currentVersion])
            {
//            if (![appStoreVersion isEqualToString:@"1"])
//            {

                trackViewURL = [[NSString alloc] initWithString:[releaseInfo objectForKey:@"trackViewUrl"]];
                NSString* msg =[releaseInfo objectForKey:@"releaseNotes"];
                _alertview =[[UIAlertView alloc] initWithTitle:@"版本升級" message:[NSString stringWithFormat:@"%@%@%@", @"新版本特性:",msg, @"\n是否升級?"] delegate:self cancelButtonTitle:@"稍後升級" otherButtonTitles:@"馬上升級", nil];
                _alertview.delegate = self;
                [_alertview show];
            }  
            
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"AFHTTPRequestOperationError: %@", error);
        
    }];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

if (alertView == _alertview) {
        if (buttonIndex==1)
        {
            NSLog(@"地址是:%@",[NSURL URLWithString:trackViewURL]);
            UIApplication *application = [UIApplication sharedApplication];
            [application openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/zhao-da-fu/id920323243?l=zh&ls=1&mt=8"]];
        }
        
    }


#define APP_URL @"http://itunes.apple.com/lookup?id=替換應用id"
//對你有用否請給評價

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章