This repository was archived by the owner on Jul 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-12
lines changed Expand file tree Collapse file tree 2 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,14 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
173173 */
174174+ (nullable IterableAPI *)sharedInstance ;
175175
176+ /* !
177+ @method
178+
179+ @abstract Sets the previously instantiated singleton instance of the API to nil
180+
181+ */
182+ + (void )clearSharedInstance ;
183+
176184// ///////////////////////////
177185// / @name Registering a token
178186// ///////////////////////////
Original file line number Diff line number Diff line change @@ -381,26 +381,34 @@ + (IterableAPI *)sharedInstance
381381 return sharedInstance;
382382}
383383
384+ // documented in IterableAPI.h
385+ + (void )clearSharedInstance
386+ {
387+ @synchronized (self) {
388+ sharedInstance = nil ;
389+ }
390+ }
391+
384392// documented in IterableAPI.h
385393+ (IterableAPI *)sharedInstanceWithApiKey : (NSString *)apiKey andEmail : (NSString *)email launchOptions : (NSDictionary *)launchOptions
386394{
387- // threadsafe way to create a static singleton https://stackoverflow.com/questions/5720029/create-singleton-using-gcds-dispatch-once-in-objective-c
388- static dispatch_once_t onceToken;
389- dispatch_once (&onceToken, ^{
390- sharedInstance = [[IterableAPI alloc ] initWithApiKey: apiKey andEmail: email launchOptions: launchOptions];
391- }) ;
392- return sharedInstance;
395+ @synchronized (self) {
396+ if (!sharedInstance){
397+ sharedInstance = [[IterableAPI alloc ] initWithApiKey: apiKey andEmail: email launchOptions: launchOptions];
398+ }
399+ return sharedInstance ;
400+ }
393401}
394402
395403// documented in IterableAPI.h
396404+ (IterableAPI *)sharedInstanceWithApiKey : (NSString *)apiKey andUserId : (NSString *)userId launchOptions : (NSDictionary *)launchOptions
397405{
398- // threadsafe way to create a static singleton https://stackoverflow.com/questions/5720029/create-singleton-using-gcds-dispatch-once-in-objective-c
399- static dispatch_once_t onceToken;
400- dispatch_once (&onceToken, ^{
401- sharedInstance = [[IterableAPI alloc ] initWithApiKey: apiKey andUserId: userId launchOptions: launchOptions];
402- }) ;
403- return sharedInstance;
406+ @synchronized (self) {
407+ if (!sharedInstance){
408+ sharedInstance = [[IterableAPI alloc ] initWithApiKey: apiKey andUserId: userId launchOptions: launchOptions];
409+ }
410+ return sharedInstance ;
411+ }
404412}
405413
406414// documented in IterableAPI.h
You can’t perform that action at this time.
0 commit comments