Skip to content

Instantly share code, notes, and snippets.

@Goles
Last active August 29, 2015 14:20
Show Gist options
  • Save Goles/5467d4476b982da9a0b4 to your computer and use it in GitHub Desktop.
Save Goles/5467d4476b982da9a0b4 to your computer and use it in GitHub Desktop.
// Header
@interface AnOperation : NSOperation
@property (nonatomic, readonly) NSString *ifa;
@property (nonatomic, assign) double timeInterval;
@end
// .m
// Tries to access a property with an exponential back-off
@implementation AnIFAOperation
- (void)main
{
_timeInterval = 0.0;
[NSTimer scheduledTimerWithTimeInterval:_timeInterval
target:self
selector:@selector(startWithTimer:)
userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] run];
}
- (BOOL)isExecuting
{
if (!_ifa) {
return YES;
}
return NO;
}
- (BOOL)isFinished
{
if (!_ifa) {
return NO;
}
return YES;
}
- (NSString *)getIFA
{
return [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
}
-(void)startWithTimer:(NSTimer *)timer
{
if (!_ifa) {
_ifa = [self getIFA];
if (!_ifa) {
_timeInterval = _timeInterval >= 1.0 ? _timeInterval * 2.0 : 1.0;
_timeInterval = MIN(60.0, _timeInterval);
[NSTimer scheduledTimerWithTimeInterval:_timeInterval
target:self
selector:@selector(startWithTimer:)
userInfo:nil
repeats:NO];
}
[timer invalidate];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment