【问题标题】:check app version using deep linking in iOS在 iOS 中使用深度链接检查应用程序版本
【发布时间】:2016-01-25 10:24:41
【问题描述】:

我们如何在 iOS 中使用深度链接检查我们应用程序的当前安装版本,以便我们可以提示用户升级应用程序。 从 Safari 浏览器,我想导航到应用程序。但根据要求,我需要检查应用程序的安装版本。 如果安装的是以前的版本,我们需要提示用户更新应用程序。

【问题讨论】:

  • 我想您可以在应用程序本身中执行此操作,然后在以下位置检查版本: - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString * )sourceApplication注解:(id)注解让你先打开应用
  • Appstore 应用程序现在会自动更新应用程序,因此如果用户禁用了此功能,那么他们可能知道他们的应用程序没有更新。
  • 我认为这只能在应用程序端而不是 safari 端完成。或者你可以尝试在应用程序中设置一个共享cookie来存储版本信息,然后在js中读取。

标签: ios objective-c iphone deep-linking deeplink


【解决方案1】:

你可以得到

您在 Xcode 目标摘要的“版本”字段中设置的值在这里:

ObjC

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

要获得 build 编号作为 NSString 变量:

NSString * CurrentbuildNo = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];

举例

你可能会这样做:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

    NSString* appIDe = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]; 
    NSURL* getpath = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appIDe]];
    NSData* JSONdata = [NSData dataWithContentsOfURL:getpath];
    NSDictionary* JSonDiCt = [NSJSONSerialization JSONObjectWithData:JSONdata options:0 error:nil];

    if ([JSonDiCt[@"resultCount"] integerValue] == 1){
        NSString* currentappStoreVersion = JSonDiCt[@"results"][0][@"version"];
        NSString* currentVersiononApp = infoDictionary[@"CFBundleShortVersionString"];
        if (![currentappStoreVersion isEqualToString:currentVersiononApp]){
            NSLog(@"Need to update");
            return YES;
        }else
        {

          //Continue your Work
  }
    }

    return YES;;
}

了解更多reference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2017-03-27
    • 1970-01-01
    • 2019-08-08
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多