强制iOS应用程序(临时分发)在一段时间后停止工作

强制iOS应用程序(临时分发)在一段时间后停止工作,ios,adhoc,Ios,Adhoc,哪种方法是防止应用程序在经过几天“测试”后被使用的最佳方法?假设我必须使用临时分发来分发我的应用程序,用户只有一周的时间进行测试,之后他应该不能使用该应用程序 提前感谢。我做了以下操作,以便在应用程序中设置beta测试的时间限制: #ifdef BETA NSString *compileDate = [NSString stringWithFormat:@"%s %s", __DATE__, __TIME__]; NSDateFormatter *df = [[NSDateFo

哪种方法是防止应用程序在经过几天“测试”后被使用的最佳方法?假设我必须使用临时分发来分发我的应用程序,用户只有一周的时间进行测试,之后他应该不能使用该应用程序


提前感谢。

我做了以下操作,以便在应用程序中设置beta测试的时间限制:

#ifdef BETA
    NSString *compileDate = [NSString stringWithFormat:@"%s %s", __DATE__, __TIME__];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MMM d yyyy HH:mm:ss"];
    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    [df setLocale:usLocale];
    NSDate *aDate = [df dateFromString:compileDate];
    NSDate *expires = [aDate dateByAddingTimeInterval:60 * 60 * 24 * 7]; // 7 days
    NSDate *now = [NSDate date];
    if ([now compare:expires] == NSOrderedDescending) {
        NSAssert(0, @"Sorry, expired");
    }
#endif
其中,
BETA
是我仅为临时构建设置的编译标志


我将此代码放在
应用程序willenterforeground:
应用程序委派方法中。

我执行以下操作以在应用程序中设置beta测试的时间限制:

#ifdef BETA
    NSString *compileDate = [NSString stringWithFormat:@"%s %s", __DATE__, __TIME__];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MMM d yyyy HH:mm:ss"];
    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    [df setLocale:usLocale];
    NSDate *aDate = [df dateFromString:compileDate];
    NSDate *expires = [aDate dateByAddingTimeInterval:60 * 60 * 24 * 7]; // 7 days
    NSDate *now = [NSDate date];
    if ([now compare:expires] == NSOrderedDescending) {
        NSAssert(0, @"Sorry, expired");
    }
#endif
其中,
BETA
是我仅为临时构建设置的编译标志


我将此代码放在
应用程序willenterforeground:
应用程序委托方法中。

每次使用Xcode构建应用程序时,它都会在应用程序包中创建一个文件
Info.plist
。我们可以从该文件中获取修改日期,以确定它自构建以来的时间

#if BETA
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    const NSTimeInterval kExpirationAge = 60 * 60 * 24 * 7;   // 7 days

    NSString* infoPlistPath = [[NSBundle mainBundle] pathForResource: @"Info" ofType: @"plist"];
    NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:infoPlistPath error:NULL];
    NSDate* buildDate = (NSDate*) [fileAttributes objectForKey:NSFileModificationDate];
    const NSTimeInterval buildAge = -[buildDate timeIntervalSinceNow];

    if (buildAge > kExpirationAge) {
        UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"App Expired"
                                                     message:@"This version is expired.  Please update to the latest version of this app."
                                                    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [av show];

        // after 10 seconds the app exits
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            exit(0);
        });
    }
}
#endif

每次使用Xcode构建应用程序时,它都会在应用程序包中创建一个文件
Info.plist
。我们可以从该文件中获取修改日期,以确定它自构建以来的时间

#if BETA
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    const NSTimeInterval kExpirationAge = 60 * 60 * 24 * 7;   // 7 days

    NSString* infoPlistPath = [[NSBundle mainBundle] pathForResource: @"Info" ofType: @"plist"];
    NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:infoPlistPath error:NULL];
    NSDate* buildDate = (NSDate*) [fileAttributes objectForKey:NSFileModificationDate];
    const NSTimeInterval buildAge = -[buildDate timeIntervalSinceNow];

    if (buildAge > kExpirationAge) {
        UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"App Expired"
                                                     message:@"This version is expired.  Please update to the latest version of this app."
                                                    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [av show];

        // after 10 seconds the app exits
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            exit(0);
        });
    }
}
#endif

有什么风险?你的测试人员不会买真货?你有多少?顺便说一句,我发现免费获得候选版本的承诺是测试人员的良好动机。换句话说,不要吝啬,让他们使用它。塞瓦,完全同意你。不幸的是,我接到了这样做的命令。@SevaAlekseyev让用户继续使用旧的测试版和给他们一份最终版本的免费拷贝之间有很大的区别。有充分的理由使测试版过期。我总是给我的测试人员提供最终版本的免费拷贝,但我不希望他们使用旧的beta。有什么风险?你的测试人员不会买真货?你有多少?顺便说一句,我发现免费获得候选版本的承诺是测试人员的良好动机。换句话说,不要吝啬,让他们使用它。塞瓦,完全同意你。不幸的是,我接到了这样做的命令。@SevaAlekseyev让用户继续使用旧的测试版和给他们一份最终版本的免费拷贝之间有很大的区别。有充分的理由使测试版过期。我总是给我的测试人员提供最终版本的免费副本,但我不希望他们使用旧的Beta。可以想象,用户可以推迟日期,仍然使用该应用程序。您可以在到期时删除一个资源,但完全重新安装将恢复该资源。最好让应用程序调用时间服务器来获取实时数据,并在这种情况下禁用它自己。看起来很棒,我将使用一个短值(5分钟)尝试一下。之后我将很高兴接受你的邀请answer@OwenHartnett这总是一种平衡。这个解决方案很简单。将对
[NSDate]
的调用替换为对NTP服务器的调用是另一种复杂程度。@Owenhartnet关于设置时间的说法是对的,但我认为这足以满足我的要求。你提出的解决方案更完整,实施起来也更耗时——这一切都取决于你希望这些Beta永远不会被使用的程度。可以想象,用户可以推迟日期,仍然使用该应用程序。您可以在到期时删除一个资源,但完全重新安装将恢复该资源。最好让应用程序调用时间服务器来获取实时数据,并在这种情况下禁用它自己。看起来很棒,我将使用一个短值(5分钟)尝试一下。之后我将很高兴接受你的邀请answer@OwenHartnett这总是一种平衡。这个解决方案很简单。将对
[NSDate]
的调用替换为对NTP服务器的调用是另一种复杂程度。@Owenhartnet关于设置时间的说法是对的,但我认为这足以满足我的要求。您提出的解决方案更加完整,实现它所需的时间也更多,这一切都取决于您希望永远不要使用这些Beta的程度。