2011-03-01 4 views
0

몇 가지 테스트 목적으로 다른 udid를 내 데이터베이스에 보내야합니다. [UIDevice currentDevice] uniqueIdentifier]는 거의 15 개 장소에서 호출되기 때문에 코드를 변경 한 다음 테스트하는 것이 매우 어려울 것입니다. 그 방법을 잠시 무시하고 다른 번호를 udid로 보내는 방법이 있습니까?ios의 uniqueIdentifier 메소드를 오버라이드

답변

1

UIDevice의 범주에서 재정의 할 수 있어야합니다. 이 같은 헤더를 작성하십시오하는 .m이 같은 다음

@interface UIDevice (overrideId) 

@property (nonatomic,readonly,retain) NSString *uniqueIdentifier 

@end 

과 :

@implementation UIDevice (overrideId) 

- (NSString *)uniqueIdentifier { 
    return @"whatever"; 
} 

@end 

를 해제하기 전에 다시 제거하는 것을 잊지 마십시오.

+0

나를 괴롭히다. +1 –

2

UIDevice에서 카테고리를 생성하고 uniqueIdentifier를 오버라이드하여 임의의 값을 반환 할 수 있습니다.

@interface UIDevice (RandomIdentifier) 

@property (nonatomic, retain, readonly) NSString *uniqueIdentifier 

@end 

@implementation UIDevice (RandomIdentifier) 

- (NSString *)uniqueIdentifier 
{ 
    return @"Randomly generated string"; 
} 

@end 
관련 문제