Skip to content

Commit

Permalink
Showing 5 changed files with 54 additions and 12 deletions.
21 changes: 17 additions & 4 deletions cieidsdk/index.d.ts
Original file line number Diff line number Diff line change
@@ -23,24 +23,31 @@ declare module "react-native-cie" {
* check if the OS support CIE autentication
*/
hasApiLevelSupport(): Promise<boolean>;

/**
* check if the device has NFC feature
*/
hasNFCFeature(): Promise<boolean>;

/**
* check if the device running the code supports CIE authentication
*/

isCIEAuthenticationSupported(): Promise<boolean>;

/**
* check if NFC is enabled
*/

isNFCEnabled(): Promise<boolean>;

/**
* register a callback to receive all Event raised while reading/writing CIE
* launch CieID app (https://play.google.com/store/apps/details?id=it.ipzs.cieid&hl=it)
* if it's installed. Otherwise the default browser is opened on the app url
*/
launchCieID(): Promise<void>;

/**
* register a callback to receive all Event raised while reading/writing CIE
*/
onEvent(callback: (event: Event) => void): void;
/**
* opens OS Settings on NFC section
@@ -52,25 +59,31 @@ declare module "react-native-cie" {
*/

onError(callback: (error: Error) => void): void;

/**
* register a callback to receive the success event containing the consent form url
*/

onSuccess(callback: (url: string) => void): void;

setAuthenticationUrl(url: string): void;

/**
* set the CIE pin. It has to be a 8 length string of 8 digits
*/
setPin(pin: string): Promise<void>;

start(): Promise<void>;

/**
* command CIE SDK to start reading/writing CIE CARD
*/
startListeningNFC(): Promise<void>;

/**
* command CIE SDK to stop reading/writing CIE CARD
*/
stopListeningNFC(): Promise<void>;

/**
* Remove all events callbacks: onEvent / onError / onSuccess
*/
19 changes: 16 additions & 3 deletions cieidsdk/index.js
Original file line number Diff line number Diff line change
@@ -20,9 +20,7 @@ class CieManager {
}
const NativeCieEmitter = new NativeEventEmitter(NativeCie);
NativeCieEmitter.addListener("onEvent", e => {
this._eventHandlers.forEach(h =>
h(e)
);
this._eventHandlers.forEach(h => h(e));
});
NativeCieEmitter.addListener("onSuccess", e => {
this._eventSuccessHandlers.forEach(h => h(e.event));
@@ -197,6 +195,21 @@ class CieManager {
});
});
};

launchCieID = () => {
if (Platform.OS === "ios") {
return Promise.reject("not implemented");
}
return new Promise((resolve, reject) => {
NativeCie.launchCieID(err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
};
}

export default new CieManager();
8 changes: 7 additions & 1 deletion cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@ import java.net.SocketTimeoutException
import java.net.UnknownHostException
import javax.net.ssl.SSLProtocolException



val CERTIFICATE_EXPIRED: CharSequence = "SSLV3_ALERT_CERTIFICATE_EXPIRED"
val CERTIFICATE_REVOKED: CharSequence = "SSLV3_ALERT_CERTIFICATE_REVOKED"

@@ -239,7 +241,11 @@ object CieIDSdk : NfcAdapter.ReaderCallback {
fun launchCieID(activity: Activity){
val cieIdPackage = "it.ipzs.cieid"
try {
activity.startActivity(activity.packageManager.getLaunchIntentForPackage(cieIdPackage))
activity.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$cieIdPackage")
))
} catch (e: PackageManager.NameNotFoundException) {
activity.startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=$cieIdPackage")))
}
17 changes: 14 additions & 3 deletions cieidsdk/src/main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt
Original file line number Diff line number Diff line change
@@ -122,12 +122,12 @@ class CieModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod

@ReactMethod
fun openNFCSettings(callback: com.facebook.react.bridge.Callback) {
val currentActivity = currentActivity
val currentActivity = getCurrentActivity()!!
if (currentActivity == null) {
callback.invoke("fail to get current activity");
} else {
CieIDSdk.openNFCSettings(currentActivity);
callback.invoke();
CieIDSdk.openNFCSettings(currentActivity)
callback.invoke()
}
}

@@ -136,4 +136,15 @@ class CieModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
callback.invoke(CieIDSdk.hasApiLevelSupport())
}

@ReactMethod
fun launchCieID(callback: com.facebook.react.bridge.Callback) {
val currentActivity = getCurrentActivity()!!
if (currentActivity == null) {
callback.invoke("fail to get current activity")
} else {
CieIDSdk.launchCieID(currentActivity)
callback.invoke()
}
}

}
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
package it.ipzs.cieidsdk.native_bridge

import com.facebook.react.ReactPackage
import com.facebook.react.bridge.JavaScriptModule
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager

0 comments on commit 5456a3a

Please sign in to comment.