Initialization
After creating your project and adding your app in the Administration portal, you will obtain a configuration file that needs to be added to the app project. Each configuration file can only be used for the app it was generated for, specifically to the application id.
- Android
- iOS
The configuration file must be copied under the assets/
directory, or in an arbitrary subdirectory of assets/
.
You will need to define a subclass of the android.app.Application
class. In your application subclass, inside the onCreate()
method, initialize AutomatID:
class App: Application() {
override fun onCreate() {
super.onCreate()
val configFile = "my/directory/automatid-myapp-android.json" // the path where you placed the configuration file, relative to the assets/ directory
val configuration = AutomatIdConfiguration.Builder().build() // see 'Customization' for configuration options
val initResult = AutomatIdManager.init(this, configFile, configuration)
if (initResult is AutomatIdInitResult.Error) {
Log.e("AutomatId", "AutomatId init error: $initResult")
}
}
}
Remember to declare the App
class in the AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name="com.myapp.App">
</application>
</manifest>
Please that the init()
method must only be called once during the application initialization. Do not call it multiple times, for example on each activity or fragment initialization.
The configuration file must be added to the Xcode project and included with the option "Target Membership".
In the UIAppDelegate
class implementation you should call the configuration method of AutomatID:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
NSError *error = nil;
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle.bundlePath stringByAppendingString:@"path/to/automatid-myapp-ios.json"];
BOOL done = [AutomatIDManager configureWithFile:path
withConfiguration:configuration
withError:&error];
if (!done || error) {
NSLog(@"Error on AutomatID configuration %@", error);
}
return YES;
}
To correctly handle screen rotation, you need to implement the following method in the UIAppDelegate class implementation:
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// NOTE: it is required to implement this method in order to rotate to landscape orientation the scanner view controller.
if (AutomatIDManager.isOnScreen) {
return [AutomatIDManager evaluateCurrentOrientation];
} else {
return UIInterfaceOrientationMaskPortrait; // whatever is your app proper orientation
}
}