檢測app版本更新根據AppStore

本文章來自於http://blog.csdn.net/xiaoxuan415315/article/details/9383453感謝作者的提供


1,用 POST 方式發送請求:

http://itunes.apple.com/search?term=你的應用程序名稱&entity=software

更加精準的做法是根據 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 數據中解析需要的數據。因爲從 appstore 查詢得到的信息是 JSON 格式的,所以需要經過解析。解析之後得到的原始數據就是如下這個樣子的:
{  
    resultCount = 1;  
    results =     (  
                {  
            artistId = 開發者 ID;  
            artistName = 開發者名稱; 
            price = 0; 
            isGameCenterEnabled = 0;  
            kind = software;  
            languageCodesISO2A =             (  
                EN  
            ); 
            trackCensoredName = 審查名稱;  
            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]]; 

發佈了28 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章