diff --git a/Source/ARTPushActivationStateMachine.m b/Source/ARTPushActivationStateMachine.m index cca151076..cf0a08190 100644 --- a/Source/ARTPushActivationStateMachine.m +++ b/Source/ARTPushActivationStateMachine.m @@ -101,7 +101,7 @@ - (void)persist { - (void)deviceRegistration:(ARTErrorInfo *)error { #ifdef TARGET_OS_IOS - ARTLocalDevice *local = _rest.device; + ARTLocalDevice *local = _rest.device_nosync; if (![[UIApplication sharedApplication].delegate conformsToProtocol:@protocol(ARTPushRegistererDelegate)]) { [NSException raise:@"ARTPushRegistererDelegate must be implemented on AppDelegate" format:@""]; @@ -156,7 +156,7 @@ - (void)deviceRegistration:(ARTErrorInfo *)error { - (void)deviceUpdateRegistration:(ARTErrorInfo *)error { #ifdef TARGET_OS_IOS - ARTLocalDevice *local = _rest.device; + ARTLocalDevice *local = _rest.device_nosync; if (![[UIApplication sharedApplication].delegate conformsToProtocol:@protocol(ARTPushRegistererDelegate)]) { [NSException raise:@"ARTPushRegistererDelegate must be implemented on AppDelegate" format:@""]; @@ -218,7 +218,7 @@ - (void)deviceUpdateRegistration:(ARTErrorInfo *)error { - (void)deviceUnregistration:(ARTErrorInfo *)error { #ifdef TARGET_OS_IOS - ARTLocalDevice *local = _rest.device; + ARTLocalDevice *local = _rest.device_nosync; id delegate = [UIApplication sharedApplication].delegate; diff --git a/Source/ARTRest.h b/Source/ARTRest.h index f96fb4b49..847f87f97 100644 --- a/Source/ARTRest.h +++ b/Source/ARTRest.h @@ -55,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) ARTPush *push; #ifdef TARGET_OS_IOS @property (nonnull, nonatomic, readonly, getter=device) ARTLocalDevice *device; +@property (nonnull, nonatomic, readonly, getter=device_nosync) ARTLocalDevice *device_nosync; #endif @end diff --git a/Source/ARTRest.m b/Source/ARTRest.m index 0c8869969..5eef26063 100644 --- a/Source/ARTRest.m +++ b/Source/ARTRest.m @@ -581,12 +581,18 @@ void ARTstopHandlingUncaughtExceptions(ARTRest *self) { } - (ARTLocalDevice *)device { + __block ARTLocalDevice *ret; + dispatch_sync(_queue, ^{ + ret = [self device_nosync]; + }); + return ret; +} + +- (NSString *)device_nosync { static dispatch_once_t once; static id device; dispatch_once(&once, ^{ - dispatch_sync(_queue, ^{ - device = [ARTLocalDevice load:self]; - }); + device = [ARTLocalDevice load:self]; }); return device; }