React-Native版本更新功能和获取商店应用版本信息
Posted suwu150
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React-Native版本更新功能和获取商店应用版本信息相关的知识,希望对你有一定的参考价值。
一、背景说明
俗话说的好,一个好的app应用,是要不停的告诉用户,我们还在维护,你可以放心的使用,放心的“充钱”
,那该怎么告诉我们亲爱的用户的,那就是通过定期不定期的更新app。
说到这里,我们就该提出该如何实现这个更新和提示的功能了,总结来说,我这里已经实现过的有两种方案:
1.设计专门的版本应用服务器,用来存储app的版本信息
2.通过专用接口,在app store或者google play中获取对应app的版本信息
对于第一种方式,就是自己搭建后段服务,每次启动应用时都去请求服务其中的数据,然后进行比对版本大小,进行版本更新。
今天我们主要来说说和实现下第二种方式,就是通过app store或者google play中获取对应api进行获取对应app 的版本信息。
二、信息要求
根据上面的背景说明,我们需要的接口是能够提供应用的那些信息呢?总结来说需要以下信息:
- 版本信息:用于对比是否提示用户升级
- 更新日志:用来说明,这次更新都有哪些细节信息
三、如何实现
1.app store信息的获取
通过get请求访问该地址:
https://itunes.apple.com/lookup?id=414478124&country=cn&entity=software
其中
- 414478124就是你项目中需要访问的id,这个可以通过在app store中分享该应用获取到
- country=cn就是国际化语言版本,国内使用cn,美国使用us,香港使用hk
- entity=software代表查询主体为软件,应用
通过上述接口可以请求到如下数据:
"resultCount":1,
"results": [
"screenshotUrls":
["https://is4-ssl.mzstatic.com/image/thumb/Purple114/v4/58/b2/69/58b2695c-e340-bf3d-ec8d-b317ae89aea3/pr_source.png/392x696bb.png", "https://is1-ssl.mzstatic.com/image/thumb/Purple114/v4/7f/34/e8/7f34e8b8-1e5b-854b-556c-5fdfa07fa947/pr_source.png/392x696bb.png", "https://is5-ssl.mzstatic.com/image/thumb/Purple124/v4/a0/aa/18/a0aa18e8-e94c-3333-0689-00841259c733/pr_source.png/392x696bb.png", "https://is1-ssl.mzstatic.com/image/thumb/Purple114/v4/83/af/72/83af72ff-a73d-9ad3-5679-234a170c08e1/pr_source.png/392x696bb.png",
"https://is2-ssl.mzstatic.com/image/thumb/PurpleSource124/v4/c3/be/79/c3be7974-1083-1c01-c12f-bf7acd88321c/0356f5e8-253a-46b0-aae1-34eef8f19d38_1.1.jpg/392x696bb.jpg",
"https://is4-ssl.mzstatic.com/image/thumb/PurpleSource124/v4/8e/93/fe/8e93fedd-a991-3fc0-2792-17900195ec10/8fb78965-9a18-4c54-b98d-54a277be936e_2.1.jpg/392x696bb.jpg"],
"ipadScreenshotUrls":["https://is1-ssl.mzstatic.com/image/thumb/Purple114/v4/cf/18/67/cf1867cf-d21e-68d9-3d9b-f321a1a80207/mzl.imkvrcco.jpg/576x768bb.jpg", "https://is2-ssl.mzstatic.com/image/thumb/Purple114/v4/d6/e8/6c/d6e86cff-8620-4ffa-fa5d-93a253ab38df/mzl.bwmfmxug.jpg/576x768bb.jpg", "https://is2-ssl.mzstatic.com/image/thumb/Purple124/v4/fb/d1/c3/fbd1c331-04a0-122f-eea1-6304c452be6e/mzl.gxopfyrb.jpg/576x768bb.jpg"], "appletvScreenshotUrls":[], "artworkUrl60":"https://is3-ssl.mzstatic.com/image/thumb/Purple115/v4/dd/af/a1/ddafa19c-cbf2-5f93-d66a-355272d31e9e/source/60x60bb.jpg", "artworkUrl512":"https://is3-ssl.mzstatic.com/image/thumb/Purple115/v4/dd/af/a1/ddafa19c-cbf2-5f93-d66a-355272d31e9e/source/512x512bb.jpg", "artworkUrl100":"https://is3-ssl.mzstatic.com/image/thumb/Purple115/v4/dd/af/a1/ddafa19c-cbf2-5f93-d66a-355272d31e9e/source/100x100bb.jpg", "artistViewUrl":"https://apps.apple.com/cn/developer/wechat/id614694882?uo=4",
"supportedDevices":["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", "iPad75-iPad75", "iPad76-iPad76", "iPhoneXS-iPhoneXS", "iPhoneXSMax-iPhoneXSMax", "iPhoneXR-iPhoneXR", "iPad812-iPad812", "iPad834-iPad834", "iPad856-iPad856", "iPad878-iPad878", "Watch4-Watch4", "iPadMini5-iPadMini5", "iPadMini5Cellular-iPadMini5Cellular", "iPadAir3-iPadAir3", "iPadAir3Cellular-iPadAir3Cellular", "iPodTouchSeventhGen-iPodTouchSeventhGen", "iPhone11-iPhone11", "iPhone11Pro-iPhone11Pro", "iPadSeventhGen-iPadSeventhGen", "iPadSeventhGenCellular-iPadSeventhGenCellular", "iPhone11ProMax-iPhone11ProMax", "iPhoneSESecondGen-iPhoneSESecondGen", "iPadProSecondGen-iPadProSecondGen", "iPadProSecondGenCellular-iPadProSecondGenCellular", "iPadProFourthGen-iPadProFourthGen", "iPadProFourthGenCellular-iPadProFourthGenCellular", "iPhone12Mini-iPhone12Mini", "iPhone12-iPhone12", "iPhone12Pro-iPhone12Pro", "iPhone12ProMax-iPhone12ProMax", "iPadAir4-iPadAir4", "iPadAir4Cellular-iPadAir4Cellular", "iPadEighthGen-iPadEighthGen", "iPadEighthGenCellular-iPadEighthGenCellular", "iPadProThirdGen-iPadProThirdGen", "iPadProThirdGenCellular-iPadProThirdGenCellular", "iPadProFifthGen-iPadProFifthGen", "iPadProFifthGenCellular-iPadProFifthGenCellular"], "advisories":["频繁/强烈的成人/性暗示题材"],
"isGameCenterEnabled":false,
"features":["iosUniversal"],
"kind":"software",
"minimumOsVersion":"11.0",
"trackCensoredName":"微信",
"languageCodesISO2A":["AR", "EN", "FR", "DE", "ID", "IT", "JA", "KO", "MS", "PT", "RU", "ZH", "ES", "TH", "ZH", "TR", "VI"],
"fileSizeBytes":"457678848",
"sellerUrl":"http://weixin.qq.com",
"formattedPrice":"免费",
"contentAdvisoryRating":"17+", "averageUserRatingForCurrentVersion":4.3577799999999999869260136620141565799713134765625,
"userRatingCountForCurrentVersion":5782630, "averageUserRating":4.3577799999999999869260136620141565799713134765625, "trackViewUrl":"https://apps.apple.com/cn/app/%E5%BE%AE%E4%BF%A1/id414478124?uo=4",
"trackContentRating":"17+",
"genreIds":["6005", "6007"],
"trackId":414478124,
"trackName":"微信",
"releaseDate":"2011-01-21T01:32:15Z",
"sellerName":"Tencent Technology (Shenzhen) Company Limited", "primaryGenreName":"Social Networking",
"isVppDeviceBasedLicensingEnabled":true,
"primaryGenreId":6005,
"currentVersionReleaseDate":"2021-04-23T09:11:17Z",
"releaseNotes":"本次更新:\\n- 解决了一些已知问题。\\n\\n最近更新:\\n- 更新了若干功能。",
"currency":"CNY",
"description":"微信是一款全方位的手机通讯应用,帮助你轻松连接全球好友。微信可以群聊、进行视频聊天、与好友一起玩游戏,以及分享自己的生活到朋友圈,让你感受耳目一新的移动生活方式。\\n\\n 为什么要使用微信:\\n • 多媒体消息:支持发送视频、图片、文本和语音消息。\\n • 群聊和通话:组建高达500人的群聊和高达9人的实时视频聊天。\\n • 语音和视频聊天:提供全球的高质量通话。\\n • 表情商店:海量动态表情,包括热门卡通人物和电影,让聊天变得更生动有趣。\\n • 朋友圈:与好友分享每个精彩瞬间,记录自己的生活点滴。\\n • 隐私保护:严格保护用户的隐私安全,是唯一一款通过TRUSTe认证的实时通讯应用。\\n • 认识新朋友:通过“雷达加朋友”、“附近的人”和“摇一摇”认识新朋友。\\n • 实时位置共享:与好友分享地理位置,无需通过语言告诉对方。\\n • 多语言:支持超过20种语言界面,并支持多国语言的消息翻译。\\n • 微信运动:支持接入Apple Watch及健康app数据,可在步数排行榜上和朋友一较高下。若需使用,可在“设置-通用-辅助功能”内启用。 \\n • 更多功能: 支持跨平台、聊天室墙纸自定义、消息提醒自定义和公众号服务等。",
"artistId":614694882,
"artistName":"WeChat",
"genres":["社交", "效率"],
"price":0.00,
"bundleId":"com.tencent.xin",
"version":"8.0.5",
"wrapperType":"software",
"userRatingCount":5782630
]
可以看到,我们能够很容易的取到bundleId、version、releaseNotes等字段,很方便我们进行版本比较,进行提示我们的应用是否更新。
2.google play信息的获取
google play信息的获取我们使用google-play-scraper库进行实现。
以上是关于React-Native版本更新功能和获取商店应用版本信息的主要内容,如果未能解决你的问题,请参考以下文章
Ios react-native 无法部署到应用商店获取 ITMS-90683:Info.plist 中缺少目的字符串
需要来自 master 分支的 react-native 功能
在 React-native 中使用 Redux Toolkit 持久化存储