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.

Revisions

  1. Goles renamed this gist Apr 28, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Goles created this gist Apr 28, 2015.
    65 changes: 65 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    // 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