在运行时获取供应配置文件的EXPIRATION日期? [英] Get the EXPIRATION date of a Provisioning Profile at Run-time?

查看:150
本文介绍了在运行时获取供应配置文件的EXPIRATION日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我经常通过ad-hoc分发方法传递给测试人员。其中一些测试人员关注并且对配置文件和季度到期有足够的了解,并且可以(如果我忘了)给我一个重建新版本供他们测试的推动。

I have an app that I routinely pass out to testers via the ad-hoc distribution method. Some of these testers are 'on the ball' and know enough about provisioning profiles and the quarterly expirations and can (if I forget) give me a nudge to rebuild a new version for them to test.

然而,有些用户似乎总是达到停止运行的程度,然后婊子和呻吟 - 尽管他们可能会忽略iOS级别的提醒。

However some of the users always seem to get to the point where it stops running and then bitch and moan about it - despite them probably dismissing the iOS level reminder.

我的问题是,我可以在运行时以编程方式获取到期日期并执行我自己的应用程序内警报或系统通知,以提醒他们下拉新版本吗?

My question is can I programatically get hold of the expiry date at runtime and do my own 'in-app' alerts or system notifications to remind them to pull down the newer version?

推荐答案

您正在寻找类似

"<key>ExpirationDate</key><date>2014-12-06T00:26:10Z</date>" in [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]

但是获取不容易!这段代码可以改进,部分内容基于其他stackoverflow帖子。注意:另一种选择是将项目plist
和/ plist之间的所有内容加载到... plist(字典)中。但由于我们已经在那里,我们只是手工找到兄弟姐妹。

But getting there is not easy! This code could be improved, parts of it were based on other stackoverflow posts. Note: Another option would be to load everything between item plist and /plist into ...a plist (dictionary). But since we're already there, we just find the sibling by hand.

- (NSString*) getExpiry{

    NSString *profilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
    // Check provisioning profile existence
    if (profilePath)
    {
        // Get hex representation
        NSData *profileData = [NSData dataWithContentsOfFile:profilePath];
        NSString *profileString = [NSString stringWithFormat:@"%@", profileData];

        // Remove brackets at beginning and end
        profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
        profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(profileString.length - 1, 1) withString:@""];

        // Remove spaces
        profileString = [profileString stringByReplacingOccurrencesOfString:@" " withString:@""];


        // Convert hex values to readable characters
        NSMutableString *profileText = [NSMutableString new];
        for (int i = 0; i < profileString.length; i += 2)
        {
            NSString *hexChar = [profileString substringWithRange:NSMakeRange(i, 2)];
            int value = 0;
            sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
            [profileText appendFormat:@"%c", (char)value];
        }

        // Remove whitespaces and new lines characters
        NSArray *profileWords = [profileText componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

        //There must be a better word to search through this as a structure! Need 'date' sibling to <key>ExpirationDate</key>, or use regex
        BOOL sibling = false;
        for (NSString* word in profileWords){
            if ([word isEqualToString:@"<key>ExpirationDate</key>"]){
                NSLog(@"Got to the key, now need the date!");
                sibling = true;
            }
            if (sibling && ([word rangeOfString:@"<date>"].location != NSNotFound)) {
                NSLog(@"Found it, you win!");
                NSLog(@"Expires: %@",word);
                return word;
            }
        }

    }

    return @"";
}

这篇关于在运行时获取供应配置文件的EXPIRATION日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆