App版本檢查跳轉(zhuǎn)更新

獲取最新版本

從自己服務(wù)器獲取最新版本號(hào)

從自己服務(wù)器上獲取沒(méi)什么好說(shuō)的,自家的約定好就行。

從蘋(píng)果服務(wù)器獲取最新版本號(hào)

獲取iTunes上APP的版本號(hào)

用 POST 方式發(fā)送請(qǐng)求https://itunes.apple.com/lookup?id=414478124(微信的id)
在瀏覽器上測(cè)試會(huì)下載一個(gè)txt文本,文本里是返回的json數(shù)據(jù),解析后是

{
    "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里你提交的信息,當(dāng)然包括你APP現(xiàn)在線上的最新版本號(hào)。

獲取當(dāng)前App版本號(hào)

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

對(duì)比三段式版本號(hào)

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

跳轉(zhuǎn)更新

注意: 下面的跳轉(zhuǎn)鏈接要看好,因?yàn)橛锌赡軙?huì)調(diào)到iTunes而不是AppStore。跳轉(zhuǎn)到iTunes的后果就是里面不是更新按鈕而是打開(kāi)按鈕,點(diǎn)擊打開(kāi)按鈕又返回到了app...這就違背了檢查更新的初衷。

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

參數(shù)解釋?zhuān)?/strong>

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
當(dāng)鏈接進(jìn)行查詢(xún)時(shí),如果沒(méi)有定義id,就有可能出現(xiàn)不同類(lèi)別的內(nèi)容,但是名字相同,例如某專(zhuān)輯的名字和某個(gè)app的名字重合。這時(shí)mt就起作用了。
ls代表link special,當(dāng)查詢(xún)的類(lèi)型為某首歌曲時(shí),不定義ls,默認(rèn)指向歌曲的專(zhuān)輯,定義后直接進(jìn)入該歌曲并試播。(貌似是這樣,apple的論壇里看到的,跟app的關(guān)系不大)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,872評(píng)論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,148評(píng)論 4 61
  • 今天看了一篇短文,分享一下。 多給孩子一些表?yè)P(yáng)和鼓勵(lì),有利于培養(yǎng)孩子良好的道德行為習(xí)慣和品質(zhì),有利于增強(qiáng)父母對(duì)孩子...
    孫彬洋媽媽閱讀 164評(píng)論 0 0
  • 在我短短20多年的生命中,絕大部分時(shí)光都是在無(wú)趣,甚至一片慘淡中度過(guò),偶爾發(fā)生的轉(zhuǎn)瞬即逝的高光時(shí)刻往往還沒(méi)讓我體會(huì)...
    東圭閱讀 409評(píng)論 0 2
  • 上午爬山,下午葛優(yōu)躺,緩過(guò)勁來(lái)黃昏騎行散步。
    周湘泉閱讀 263評(píng)論 0 2

友情鏈接更多精彩內(nèi)容