Use GCD instead of threads #27

wants to merge 4 commits into


None yet

5 participants


Was previously creating a new thread for every call to +userDidSignificantEvent, +appEnteredForeground, and +appLaunched, which is unnecessarily expensive (especially for apps calling userDidSignificantEvent often).

triplef added some commits Jul 22, 2011
@triplef triplef Use #ifs for APPIRATER_DEBUG instead of runtime check. 9c660ca
@triplef triplef Use GCD instead of threads.
Was previously creating a new thread for every call to +userDidSignifica
ntEvent, +appEnteredForeground, and +appLaunched.

I just revised your version with this dispatch_once singleton:
I've been reading up on race conditions with older style singletons and I "believe" this style is safe, secure and thread safe.

#pragma mark GCD Singleton
static Appirater *appirater = nil;

  • (Appirater*)sharedInstance {

    if (appirater) return appirater;

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    appirater = [[Appirater alloc] init];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:@"UIApplicationWillResignActiveNotification" object:nil];
    return appirater;


Good idea! Just changed it to use dispatch_once. Thanks!


np - I've been testing your commit the last few days and no problems - nice update!


I like the idea of using GCD, but I need to make sure Appirater remains compatible for developers who still need to deploy on iOS3 devices (myself included :-/ ).


@arashpayan - no problem, except Apple will be making that decision for you (meaning say around iOS 5.1 or 5.2, Apple will bump the min OS and remove 3.x from the list, for new apps). :-) Of course for Game center apps all these "rate my app" projects will no longer be needed in 5.x ( i'll be keeping it in my apps for non-game center users, which there are still a lot of)


+1, can we please use this? It's been 6 months, iOS 3 is barely relevant any more.


iOS 6 is now out... no one cares about the first iteration iPhone. Time to merge this into master? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment