iOSはiTunes searchでバージョンの更新を検出し、ユーザーに更新を促す!


appバージョンの更新を検出する場合は、現在実行されているappバージョンのバージョン情報とappstoreで公開されている最新バージョンの情報を取得する必要があります.
現在の実行バージョン情報はinfo.plistファイルのbundle versionで取得:
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    CFShow(infoDic);
    
    NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];

これで現在実行されているappのバージョンが取得されます
現在のapp storeの最新バージョンを取得するには、2つの方法があります.
一、ある特定のサーバ上でappの最新バージョン情報を発行し、記憶し、必要に応じてそのサーバにクエリーを要求する.
二、app storeからクエリーして、appの作者、接続、バージョンなどを取得することができます.公式関連文書
www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.htm
具体的な手順は以下の通りである:1、POST方式で要求を送信する:http://itunes.apple.com/search?term=あなたのアプリケーション名&entity=ソフトウェアのより正確な方法はappのidに基づいて検索することです.http://itunes.apple.com/lookup?id=あなたのアプリのID
#define APP_URL http://itunes.apple.com/lookup?id=あなたのアプリのID
あなたのアプリのIDはitunes connectのApple IDです
2,得られたresponseデータから必要なデータを解析する.アプリストアから検索した情報はJSON形式なので解析が必要です.解析後に得られた元のデータは,{resultCount=1;results=({artistId=開発者ID;artistName=開発者名;price=0;isGameCenter Enabled=0;kind=software;languageCodesISO 2 A=(EN);trackCentoredName=レビュー名;trackContentRating=評価;trackId=アプリケーションID;trackName=アプリケーション名「;trackViewUrl=アプリケーション紹介サイト;userRatingCount=ユーザー評価;userRatingCountForCurrentVersion=1;version=バージョン番号;wrapperType=software;})}}results配列を取得すると次のようになります.:NSDictionary *jsonData = [dataPayload JSONValue];  NSArray *infoArray = [jsonData objectForKey:@"results"];  NSDictionary *releaseInfo = [infoArray objectAtIndex:0];  NSString *latestVersion = [releaseInfo objectForKey:@"version"];  NSString *trackViewUrl = [releaseInfo objectForKey:@"trackViewUrl"];trackViewUrlの実際のアドレスをコピーしてブラウザで開くと、appstoreのアプリケーションの紹介ページが開きます.もちろん、コードでsafariを呼び出して開くこともできます.UIApplication *application = [UIApplication sharedApplication];  [application openURL:[NSURL URLWithString:trackViewUrl]];  
-(void)onCheckVersion:(NSString *)currentVersion
{
    NSString *URL = APP_URL;
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:URL]];
    [request setHTTPMethod:@"POST"];
    NSHTTPURLResponse *urlResponse = nil;
    NSError *error = nil;
    NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
    
    NSString *results = [[NSString alloc] initWithBytes:[recervedData bytes] length:[recervedData length] encoding:NSUTF8StringEncoding];
    NSDictionary *dic = [results JSONValue];
    NSArray *infoArray = [dic objectForKey:@"results"];
    if ([infoArray count]) {
        NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
        NSString *lastVersion = [releaseInfo objectForKey:@"version"];
        
        if (![lastVersion isEqualToString:currentVersion]) {
            trackViewURL = [releaseInfo objectForKey:@"trackViewUrl"];
            UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"  " message:@"       ,      ?" delegate:self cancelButtonTitle:@"  " otherButtonTitles:@"  ", nil] autorelease];
            [alert show];
        }
    }
}

参考ブログ:http://hi.baidu.com/yanh105/item/7378a98ffca6a8804414cfa0