「ios開発」IOSでアプリの最新バージョンを取得する方法

操作手順
1.http://itunes.apple.com/lookup?id=アプリケーションID
#define APP_URL http://itunes.apple.com/lookup?id=アプリケーションID

2.response応答から得られたデータを分析する
jsonデータ形式:
{
resultCount = 1;
results = (
{
artistId = 開発者 ID;
artistName = 開発名;
price = 0;
isGameCenterEnabled = 0;
kind = software;
languageCodesISO2A = (
EN
);
trackCensoredName = 審査名前;
trackContentRating = 評価;
trackId = アプリケーションID;
trackName = アプリケーション名";
trackViewUrl =アプリケーションURL;
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"];

 

3.バージョンをチェックする
コード下記:
-(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:@"trackVireUrl"];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"更新" message:@"新バージョンがある,更新しますか?" delegate:self cancelButtonTitle:@"キャンセル" otherButtonTitles:@"更新", nil] autorelease];
[alert show];
}
}
}

IOS

Posted by arkgame