|
@@ -3,54 +3,46 @@ using System.Json;
|
|
|
using System.Net.Http;
|
|
|
using Foundation;
|
|
|
using System.Threading.Tasks;
|
|
|
-using System.Text.RegularExpressions;
|
|
|
using System.Globalization;
|
|
|
|
|
|
[assembly: Xamarin.Forms.Dependency(typeof(InABox.Mobile.iOS.Version_iOS))]
|
|
|
namespace InABox.Mobile.iOS
|
|
|
{
|
|
|
-
|
|
|
- // internal static class iOS_VersionExtensions
|
|
|
- // {
|
|
|
- // public static string MakeSafeForAppStoreShortLinkUrl(this string value)
|
|
|
- // {
|
|
|
- // // Reference: https://developer.apple.com/library/content/qa/qa1633/_index.html
|
|
|
- //
|
|
|
- // var regex = new Regex(@"[©™®!¡""#$%'()*+,\\\-.\/:;<=>¿?@[\]^_`{|}~]*");
|
|
|
- //
|
|
|
- // var safeValue = regex.Replace(value, "")
|
|
|
- // .Replace(" ", "")
|
|
|
- // .Replace("&", "and")
|
|
|
- // .ToLower();
|
|
|
- //
|
|
|
- // return safeValue;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// <see cref="ILatestVersion"/> implementation for iOS.
|
|
|
- /// </summary>
|
|
|
+
|
|
|
public class Version_iOS : IAppVersion
|
|
|
{
|
|
|
string _bundleName => NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleName").ToString();
|
|
|
string _bundleIdentifier => NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleIdentifier").ToString();
|
|
|
string _bundleVersion => NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
|
|
|
JsonValue _appstoreInfo = null;
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
+
|
|
|
public string InstalledVersionNumber
|
|
|
{
|
|
|
get => _bundleVersion;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- private async Task CheckAppStoreInfo(string appName)
|
|
|
+
|
|
|
+ public async Task<bool> IsUsingLatestVersion()
|
|
|
{
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var info = await GetLatestVersion(false);
|
|
|
+ return String.IsNullOrWhiteSpace(info.Version)
|
|
|
+ || (Version.Parse(info.Version).CompareTo(Version.Parse(_bundleVersion)) <= 0);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ PRS.Mobile.MobileLogging.Log(e,"AppStore");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- if (_appstoreInfo != null)
|
|
|
- return;
|
|
|
|
|
|
- var url = $"http://itunes.apple.com/lookup?bundleId={appName}";
|
|
|
+ private async Task CheckAppStoreInfo()
|
|
|
+ {
|
|
|
+
|
|
|
+ // http://itunes.apple.com/lookup?bundleId=com.prsdigital.prssiteapp
|
|
|
+ var url = $"http://itunes.apple.com/lookup?bundleId={_bundleIdentifier}";
|
|
|
|
|
|
using (var request = new HttpRequestMessage(HttpMethod.Get, url))
|
|
|
{
|
|
@@ -90,49 +82,22 @@ namespace InABox.Mobile.iOS
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <inheritdoc />
|
|
|
- public async Task<bool> IsUsingLatestVersion()
|
|
|
- {
|
|
|
- string latestversion = string.Empty;
|
|
|
- try
|
|
|
- {
|
|
|
- latestversion = await GetLatestVersionNumber(false);
|
|
|
- return String.IsNullOrWhiteSpace(latestversion) || (Version.Parse(latestversion).CompareTo(Version.Parse(_bundleVersion)) <= 0);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new LatestVersionException($"Error comparing current app version number with latest. Bundle version={_bundleVersion} and lastest version={latestversion} .", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private string _latestversionnumber = "";
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- public async Task<string> GetLatestVersionNumber(bool force)
|
|
|
- {
|
|
|
- return await GetLatestVersionNumber(_bundleIdentifier, force);
|
|
|
- }
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- public async Task<string> GetLatestVersionNumber(string appName, bool force)
|
|
|
+ private AppInfo _info = null;
|
|
|
+
|
|
|
+ public async Task<AppInfo> GetLatestVersion(bool force)
|
|
|
{
|
|
|
+
|
|
|
if (force)
|
|
|
- _latestversionnumber = "";
|
|
|
+ _info = null;
|
|
|
|
|
|
- if (!String.IsNullOrWhiteSpace(_latestversionnumber))
|
|
|
- return _latestversionnumber;
|
|
|
+ if (_info != null)
|
|
|
+ return _info;
|
|
|
|
|
|
- String version = "";
|
|
|
|
|
|
- if (string.IsNullOrWhiteSpace(appName))
|
|
|
- {
|
|
|
- throw new ArgumentNullException(nameof(appName));
|
|
|
- }
|
|
|
-
|
|
|
- await CheckAppStoreInfo(appName);
|
|
|
-
|
|
|
+ _info = new AppInfo();
|
|
|
try
|
|
|
{
|
|
|
+ await CheckAppStoreInfo();
|
|
|
if (_appstoreInfo.ContainsKey("results"))
|
|
|
{
|
|
|
var results = _appstoreInfo["results"];
|
|
@@ -140,40 +105,30 @@ namespace InABox.Mobile.iOS
|
|
|
{
|
|
|
var result = results[0];
|
|
|
if (result.ContainsKey("version"))
|
|
|
- version = result["version"];
|
|
|
+ _info.Version = result["version"];
|
|
|
+ if (result.ContainsKey("releaseDate") && DateTime.TryParse(result["releaseDate"],out DateTime release))
|
|
|
+ _info.Date = release;
|
|
|
+ if (result.ContainsKey("releaseNotes"))
|
|
|
+ _info.Notes = result["releaseNotes"];
|
|
|
}
|
|
|
}
|
|
|
- //version = _appstoreInfo["results"]?[0]?["version"] ?? "";
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
+ MobileLogging.Log(e,"AppStore");
|
|
|
}
|
|
|
- return version;
|
|
|
+ return _info;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
public Task OpenAppInStore()
|
|
|
{
|
|
|
- return OpenAppInStore(_bundleName);
|
|
|
- }
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- public Task OpenAppInStore(string appName)
|
|
|
- {
|
|
|
- if (string.IsNullOrWhiteSpace(appName))
|
|
|
- {
|
|
|
- throw new ArgumentNullException(nameof(appName));
|
|
|
- }
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
-
|
|
|
var location = RegionInfo.CurrentRegion.Name.ToLower();
|
|
|
var trackid = _appstoreInfo["results"][0]["trackId"];
|
|
|
-
|
|
|
- var url = String.Format("https://itunes.apple.com/{0}/app/{1}/id{2}?mt=8",location,appName,trackid);
|
|
|
-
|
|
|
+ var url = String.Format("https://itunes.apple.com/{0}/app/{1}/id{2}?mt=8",location,_bundleName,trackid);
|
|
|
//appName = appName.MakeSafeForAppStoreShortLinkUrl();
|
|
|
|
|
|
#if __IOS__
|