5
+(Service *) sharedInstance
{
    static LocationService *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{              <<<< Crash
        instance = [[self alloc]init];
    });
    return instance;
}

I am using the above shown code to create a singleton instance of service in my application. This is called from "AppDelegate application:willFinishLaunchingWithOptions:".

For most of the users, this code works fine. But for 2 users, the app crashes at "dispatch_once(&onceToken, ^{ " line.

They deleted the app and re-installed it. But they still see the issue. Only these 2 users are facing this issue. Others have never seen it. I have the .dsym, .crash and other relevant files to do further debugging. Just wanted to know how should I proceed with it? If someone has seen similar issue how did they proceed with fixing it?

Parin Shah
  • 189
  • 2
  • 11

1 Answers1

-1

Don't use self. Because self is not available before the initilization of class. Instead you can use class name as follows.

+(Service *) sharedInstance
{
static LocationService *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{            
    instance = [[Service  alloc]init];
});
return instance;
}
Satyanarayana
  • 1,059
  • 6
  • 16