In the main header class of the application, add a static method called sharedController (for example, I am using the fictional class name MainApp):
==================
MainApp.h:
______________
+(uniMag*) sharedController;
======================
Then in the main method class of the application, add the code for it, which is a static variable and the sharedController definition:
================
MainApp.m
_____________
static volatile uniMag *singletonUnimag = nil;
+(uniMag*) sharedController{
//Accesses a singleton instance of device class.
static uniMag *SharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SharedInstance = [uniMag new];
});
singletonUnimag = SharedInstance;
return SharedInstance;
}
========================
Instead of initializing the device as:
unimag* myDevice = [unimag new]; ( or [[unimag alloc] init] )
you use
unimag* myDevice = [MainApp sharedController];
With a singleton, and without any separate activation effort, even on the first time, functions such as ([MainApp sharedController] ReadCardSwipe) may be used.
l