App版本檢查跳轉更新

獲取最新版本

從自己服務器獲取最新版本號

從自己服務器上獲取沒什麼好說的,自家的約定好就行。

從蘋果服務器獲取最新版本號

獲取iTunes上APP的版本號

用 POST 方式發送請求https://itunes.apple.com/lookup?id=414478124(微信的id)
在瀏覽器上測試會下載一個txt文本,文本里是返回的json數據,解析後是

{
    "resultCount":1,
    "results":[
        {
            "ipadScreenshotUrls":[
                "http://is2.mzstatic.com/image/thumb/Purple117/v4/a1/69/ac/a169ac6e-312b-309c-c11a-89ba48a01d39/source/576x768bb.jpg",
                "http://is5.mzstatic.com/image/thumb/Purple117/v4/b7/53/6e/b7536e0b-0a6d-ec79-c146-0e29db308817/source/576x768bb.jpg",
                "http://is5.mzstatic.com/image/thumb/Purple127/v4/b7/78/80/b77880be-8629-88ab-8e31-1debff900e83/source/576x768bb.jpg",
                "http://is1.mzstatic.com/image/thumb/Purple127/v4/66/28/fe/6628fe0d-66f1-e476-d9a2-7828cb32cdcc/source/576x768bb.jpg"
            ],
            "appletvScreenshotUrls":[

            ],
            "artworkUrl60":"http://is1.mzstatic.com/image/thumb/Purple128/v4/58/ae/73/58ae73a0-1bbe-bd36-46e8-38b9e5d0641e/source/60x60bb.jpg",
            "artworkUrl512":"http://is1.mzstatic.com/image/thumb/Purple128/v4/58/ae/73/58ae73a0-1bbe-bd36-46e8-38b9e5d0641e/source/512x512bb.jpg",
            "artworkUrl100":"http://is1.mzstatic.com/image/thumb/Purple128/v4/58/ae/73/58ae73a0-1bbe-bd36-46e8-38b9e5d0641e/source/100x100bb.jpg",
            "artistViewUrl":"https://itunes.apple.com/us/developer/wechat/id614694882?uo=4",
            "kind":"software",
            "features":[
                "iosUniversal"
            ],
            "supportedDevices":[
                "iPad2Wifi-iPad2Wifi",
                "iPad23G-iPad23G",
                "iPhone4S-iPhone4S",
                "iPadThirdGen-iPadThirdGen",
                "iPadThirdGen4G-iPadThirdGen4G",
                "iPhone5-iPhone5",
                "iPodTouchFifthGen-iPodTouchFifthGen",
                "iPadFourthGen-iPadFourthGen",
                "iPadFourthGen4G-iPadFourthGen4G",
                "iPadMini-iPadMini",
                "iPadMini4G-iPadMini4G",
                "iPhone5c-iPhone5c",
                "iPhone5s-iPhone5s",
                "iPadAir-iPadAir",
                "iPadAirCellular-iPadAirCellular",
                "iPadMiniRetina-iPadMiniRetina",
                "iPadMiniRetinaCellular-iPadMiniRetinaCellular",
                "iPhone6-iPhone6",
                "iPhone6Plus-iPhone6Plus",
                "iPadAir2-iPadAir2",
                "iPadAir2Cellular-iPadAir2Cellular",
                "iPadMini3-iPadMini3",
                "iPadMini3Cellular-iPadMini3Cellular",
                "iPodTouchSixthGen-iPodTouchSixthGen",
                "iPhone6s-iPhone6s",
                "iPhone6sPlus-iPhone6sPlus",
                "iPadMini4-iPadMini4",
                "iPadMini4Cellular-iPadMini4Cellular",
                "iPadPro-iPadPro",
                "iPadProCellular-iPadProCellular",
                "iPadPro97-iPadPro97",
                "iPadPro97Cellular-iPadPro97Cellular",
                "iPhoneSE-iPhoneSE",
                "iPhone7-iPhone7",
                "iPhone7Plus-iPhone7Plus",
                "iPad611-iPad611",
                "iPad612-iPad612",
                "iPad71-iPad71",
                "iPad72-iPad72",
                "iPad73-iPad73",
                "iPad74-iPad74",
                "iPhone8-iPhone8",
                "iPhone8Plus-iPhone8Plus",
                "iPhoneX-iPhoneX"
            ],
            "screenshotUrls":[
                "http://is5.mzstatic.com/image/thumb/Purple127/v4/23/c0/dd/23c0dde6-f43b-d13b-ff12-f3dd0fc2911d/source/392x696bb.jpg",
                "http://is1.mzstatic.com/image/thumb/Purple122/v4/33/fa/38/33fa3803-cbbe-19e2-3225-efda30868629/source/392x696bb.jpg",
                "http://is4.mzstatic.com/image/thumb/Purple127/v4/84/94/a5/8494a587-b41d-843a-5f62-245124cf12f7/source/392x696bb.jpg",
                "http://is3.mzstatic.com/image/thumb/Purple117/v4/4b/35/22/4b352282-6178-8b3a-94f4-4a20df147ea1/source/392x696bb.jpg",
                "http://is4.mzstatic.com/image/thumb/Purple127/v4/43/8c/0a/438c0a11-f8b4-2458-6953-1003b293c7f1/source/392x696bb.jpg"
            ],
            "advisories":[
                "Infrequent/Mild Sexual Content and Nudity"
            ],
            "isGameCenterEnabled":false,
            "averageUserRatingForCurrentVersion":4.5,
            "trackCensoredName":"WeChat",
            "languageCodesISO2A":[
                "AR",
                "ZH",
                "EN",
                "FR",
                "DE",
                "HE",
                "HI",
                "ID",
                "IT",
                "JA",
                "KO",
                "MS",
                "PL",
                "PT",
                "RU",
                "ZH",
                "ES",
                "TH",
                "ZH",
                "TR",
                "VI"
            ],
            "fileSizeBytes":"235411456",
            "sellerUrl":"http://www.wechat.com",
            "contentAdvisoryRating":"12+",
            "userRatingCountForCurrentVersion":3578,
            "trackViewUrl":"https://itunes.apple.com/us/app/wechat/id414478124?mt=8&uo=4",
            "trackContentRating":"12+",
            "formattedPrice":"Free",
            "sellerName":"Tencent Technology (Shenzhen) Company Limited",
            "minimumOsVersion":"8.0",
            "genreIds":[
                "6005",
                "6007"
            ],
            "currentVersionReleaseDate":"2017-12-28T06:20:47Z",
            "wrapperType":"software",
            "version":"6.6.1",
            "description":"WeChat is a messaging and calling app that allows you to easily connect with family & friends across countries. It's the all-in-one communications app for text (SMS/MMS), voice and video calls, Moments, photo sharing, and games.

WHY USE WECHAT:
• MULTIMEDIA MESSAGING: Send video, image, text, and voice messages.
• GROUP CHAT & CALLS: Create group chats with up to 500 people and group video calls up to 9 people. 
• FREE VOICE & VIDEO CALLS: High-quality free calls to anywhere in the world.
• WECHAT OUT CALLS: Make calls to landlines and mobile around the globe at low rates (in certain regions only).
• STICKER GALLERY: Hundreds of free, fun, animated stickers to express your feelings from some of your favorite cartoons and movies.
• MOMENTS: Share your best moments on your personal photo stream.
• BETTER PRIVACY: WeChat gives you the highest level of control over your privacy. It's the only messaging app to be certified by TRUSTe.
• MEET NEW FRIENDS: Use “Friend Radar”, “People Nearby” and “Shake” to meet others. 
• REALTIME LOCATION: Instead of having to tell others where you are, just use real-time location sharing.
• LANGUAGE SUPPORT: Localized in 20 different languages and can translate messages to any language.
• WeRun-WeChat: Access HealthKit data and challenge friends to beat their scores via the "WeRun-WeChat" Official Account.
• AND MORE: Desktop app, custom wallpapers, custom notifications, and Official Accounts.",
            "artistId":614694882,
            "artistName":"WeChat",
            "genres":[
                "Social Networking",
                "Productivity"
            ],
            "price":0,
            "currency":"USD",
            "trackId":414478124,
            "trackName":"WeChat",
            "bundleId":"com.tencent.xin",
            "isVppDeviceBasedLicensingEnabled":true,
            "primaryGenreName":"Social Networking",
            "releaseDate":"2011-01-21T01:32:15Z",
            "releaseNotes":"Latest Updates:
- Notes in Favorites can be saved as an image, making it easier to share to Moments.
- Sent a message with a typo? Recall the message and immediately edit your message.

Recent Updates:
- Compatible with iPhone X
- Edit videos before sending
- Disable alerts for likes or comments to Moments posts
- Search files, photos and links within your chat history
- Information on how group members joined a group now available to group owners
- Preview and edit selected photos before sending them to friends",
            "primaryGenreId":6005,
            "averageUserRating":4.5,
            "userRatingCount":44769
        }
    ]
}

全是iTunes裏你提交的信息,當然包括你APP現在線上的最新版本號。

獲取當前App版本號

NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

對比三段式版本號

+ (BOOL)isNewestVersion:(NSString *)version
{
    NSString *currentV = [APPVERSION stringByReplacingOccurrencesOfString:@"." withString:@""];
    NSString *onlineV = [version stringByReplacingOccurrencesOfString:@"." withString:@""];
    if (onlineV.integerValue > currentV.integerValue) {
        return NO;
    }else {
        return YES;
    }
}

跳轉更新

注意: 下面的跳轉鏈接要看好,因爲有可能會調到iTunes而不是AppStore。跳轉到iTunes的後果就是裏面不是更新按鈕而是打開按鈕,點擊打開按鈕又返回到了app…這就違背了檢查更新的初衷。

//跳轉到 iTunes 
NSURL *url1 = [NSURL URLWithString:@"itms://itunes.apple.com/cn/app/idxxxxxxxx?mt=8"];
//跳轉到 AppStore
NSURL *url2 = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/idxxxxxxxx?mt=8"];
//跳轉到 AppStore
NSURL *url3 = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/idxxxxxxxx?mt=8"];
[[UIApplication sharedApplication] openURL:url2];

參數解釋:

mt:meta-type 有效值如下

1 Music
2 Podcasts
3 Audiobooks
4 TV Shows
5 Music Videos
6 Movies
7 iPod Games
8 Mobile Software Applications
9 Ringtones
10 iTunes U
11 E-Books
12 Desktop Apps
當鏈接進行查詢時,如果沒有定義id,就有可能出現不同類別的內容,但是名字相同,例如某專輯的名字和某個app的名字重合。這時mt就起作用了。
ls代表link special,當查詢的類型爲某首歌曲時,不定義ls,默認指向歌曲的專輯,定義後直接進入該歌曲並試播。(貌似是這樣,apple的論壇裏看到的,跟app的關係不大)

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