SDK Set Up
Before you call functions to communicate with Med-ic and eCAP smart packaging, the CertiScan Mobile SDKs must be added to your project and configured properly.
CertiScan iOS SDK
Copy the CertiScanSDK.framework to the directory of your iOS project and add it to the project. Make sure “Copy items if needed” is selected.
Turn on Near Field Communication Tag Reading under the Capabilities tab for the project’s target. (see Add a capability to a target and Building an NFC Tag-Reader App)
Make sure CoreNFC.framework and CertiScanSDK.framework are added to the “Frameworks, Libraries, and Embedded Content” for the project’s target.
Add properties to Info of the project’s target for NFC usage.
- Select Info.
- Expand Custom iOS Target Properties.
- Add “Privacy - NFC Scan Usage Description” and write the description for NFC scan usage.
- Add “ISO7816 application identifiers for NFC Tag Reader Session” and set “D2760000850101” to the value of “Item 0”.
Verify Your Set Up
Verify by calling the function NFCAPIManager.getSDKInfo(...)
. This will return the SDK information if the CertiScanSDK.framework is added to your project successfully.
- Swift
- Objective-C
import CertiScanSDK
func verification() {
NFCAPIManager.getSDKInfo
{ responseJsonString in
if let output = responseJsonString {
print("output = \(output)")
}
}
}
#import <CertiScanSDK/CertiScanSDK-Swift.h>
-(void) verification{
[NFCAPIManager getSDKInfoWithCompletionHandler:
^(NSString * _Nullable responseJsonString) {
NSLog(@"output=%@", responseJsonString);
}];
}
output={
"name" : "CertiScanSDK",
"version" : "1.0",
"build" : "1"
}
CertiScan Android SDK
Copy the CertiScanSDK.aar to the “libs” directory of your Android project.
In build.gradle, set compileSdkVersion to the level 31 or higher. And minSdkVersion must be the level 23 or higher.
// build.gradle (:app)
android {
compileSdk 31
defaultConfig {
minSdk 23
targetSdk 31
}
}Modify “implementation fileTree” in build.gradle of the Module app as below:
// build.gradle (:app)
dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}Sync project with Gradle files (in the menu "File").
cautionYou must
sync project with Gradle files
after CertiScanSDK.aar is added or replaced. Otherwise, Android Studio might not recognize it properly.Add NFC permission to AndroidManifest.xml.
<manifest>
<uses-permission android:name="android.permission.NFC" />
<!-- optional-->
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
</manifest>Set “required” as true to the uses-feature element "android.hardware.nfc" so that your application shows up in Google Play only for devices that have NFC hardware. If your application uses NFC functionality, but that functionality is not crucial to your application, you can omit the uses-feature element and check for NFC availability at runtime by checking to see if “getDefaultAdapter()” is null.
Create “filter_nfc.xml” file to “/res/xml/” directory of your project. Add the following to it.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
</tech-list>
</resources>
Add NFCReaderActivity to AndroidManifest.xml, and also configure your Activity with intent-filter and meta-data.
<manifest>
<application>
<activity android:name="CertiScanSDK.NFCReaderActivity"
android:launchMode="singleTask"
android:theme="@style/Theme.Transparent"
android:exported="false">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc" />
</activity>
<activity android:name="your Activity"
android:exported="true">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc" />
</activity>
</application>
</manifest>If your app targets Android 12 and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the
android:exported
attribute for these app components.
Verify Your Set Up
Verify by calling the method NFCAPIManager.getSDKInfo(...)
. This will return the SDK information if the CertiScanSDK.aar is added to your project successfully.
- Kotlin
- Java
import CertiScanSDK.NFCAPIManager
import CertiScanSDK.NFCReaderStatus
fun verification() {
val callback = object : NFCAPIManager.Callback {
override fun OnComplete(responseJsonString: String?) {
Log.i("CertiScan", "output=$responseJsonString")
}
override fun onNFCReaderStatusChanged(status: NFCReaderStatus?) {
}
}
NFCAPIManager.getSDKInfo(callback)
}
import CertiScanSDK.NFCAPIManager;
import CertiScanSDK.NFCReaderStatus;
void verification(){
NFCAPIManager.getSDKInfo(new NFCAPIManager.Callback()
{
@Override
public void OnComplete(String output) {
Log.i("CertiScan", "output=" + output);
}
@Override
public void onNFCReaderStatusChanged(NFCReaderStatus status) {
}
});
}
output={
"name" : "CertiScanSDK",
"version" : "1.0",
"build" : "1"
}