我需要向我的数据库发送一个不同的 udid 以进行一些测试。由于 [UIDevice currentDevice] uniqueIdentifier] 在近 15 个地方被调用,因此我很难更改代码然后进行测试。有没有办法暂时覆盖该方法并发送另一个号码作为 udid ?
2 回答
2
您可以在 UIDevice 上创建一个类别并覆盖 uniqueIdentifier 以返回一个随机值。
@interface UIDevice (RandomIdentifier)
@property (nonatomic, retain, readonly) NSString *uniqueIdentifier
@end
@implementation UIDevice (RandomIdentifier)
- (NSString *)uniqueIdentifier
{
return @"Randomly generated string";
}
@end
于 2011-03-01T03:13:57.377 回答
1
您应该能够在 UIDevice 上的类别中覆盖它。创建一个像这样的标题:
@interface UIDevice (overrideId)
@property (nonatomic,readonly,retain) NSString *uniqueIdentifier
@end
然后是这样的 .m :
@implementation UIDevice (overrideId)
- (NSString *)uniqueIdentifier {
return @"whatever";
}
@end
不要忘记在释放之前再次删除它。
于 2011-03-01T03:10:55.077 回答