+(Service *) sharedInstance { static LocationService *instance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ <<<< Crash instance = [[self alloc]init]; }); return instance; }
我正在使用上面显示的代码在我的应用程序中创建一个单例服务实例.这是从“AppDelegate application:willFinishLaunchingWithOptions:”调用的.
对于大多数用户,此代码工作正常.但对于2个用户,该应用程序崩溃在“dispatch_once(& onceToken,^ {”行.
他们删除了应用并重新安装了它.但他们仍然看到了这个问题.只有这两个用户正面临这个问题.其他人从未见过它.我有.dsym,.crash和其他相关文件来做进一步的调试.只是想知道我该如何处理它?如果有人看到过类似的问题,他们是如何着手修复它的?
解决方法
不要使用自我.因为在课堂开始之前自己不可用.相反,您可以使用类名如下.
+(Service *) sharedInstance { static LocationService *instance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ instance = [[Service alloc]init]; }); return instance; }