出于一些测试目的,我需要发送一个不同的udid到我的数据库。由于UIDevice currentDevice uniqueIdentifier]几乎在15个地方被调用,所以我很难更改代码然后进行测试。有没有办法覆盖该方法一段时间,并发送另一个数字作为udid?
发布于 2011-03-01 11:10:55
您应该能够在UIDevice上的类别中覆盖它。创建标题,如下所示:
@interface UIDevice (overrideId)
@property (nonatomic,readonly,retain) NSString *uniqueIdentifier
@end然后是这样的.m:
@implementation UIDevice (overrideId)
- (NSString *)uniqueIdentifier {
return @"whatever";
}
@end在发布之前,不要忘记再次删除它。
发布于 2011-03-01 11:13:57
您可以在UIDevice上创建一个类别,并覆盖uniqueIdentifier以返回一个随机值。
@interface UIDevice (RandomIdentifier)
@property (nonatomic, retain, readonly) NSString *uniqueIdentifier
@end
@implementation UIDevice (RandomIdentifier)
- (NSString *)uniqueIdentifier
{
return @"Randomly generated string";
}
@endhttps://stackoverflow.com/questions/5150029
复制相似问题