Otpless ionic plugin support for android and ios apps
npm install otpless-ionicOtpless ionic plugin support for android and ios apps
``bash`
npm install otpless-ionic
npx cap sync
``
import {OtplessManager} from 'otpless-ionic';
#### In your login component create the instance of OtplessManager.
``
let manager = new OtplessManager()
#### Call showOtplessLoginPage method on button click or while loading component to launch OTPless sdk
``
let jsonParams = {appId: "APP_ID"}
const data = await manager.showOtplessLoginPage(jsonParams);
pod install
`* Add below lines in info.plist file
`
CFBundleURLTypes
CFBundleURLSchemes
CFBundleTypeRole
Editor
CFBundleURLName
otpless
LSApplicationQueriesSchemes
whatsapp
otpless
gootpless
com.otpless.ios.app.otpless
googlegmail
NSAppTransportSecurity
NSAllowsArbitraryLoads
NSExceptionDomains
80.in.safr.sekuramobile.com
NSIncludesSubdomains
NSTemporaryExceptionAllowsInsecureHTTPLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.1
partnerapi.jio.com
NSIncludesSubdomains
NSTemporaryExceptionAllowsInsecureHTTPLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.1
`* Add application method in your AppDelegate
`
import OtplessSDK
`
`
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if (Otpless.sharedInstance.isOtplessDeeplink(url: url)) {
Otpless.sharedInstance.processOtplessDeeplink(url: url)
return true
}
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}
}
`
$3
* In MainActivity register the plugin, before calling super.onCreate.
`
import com.otpless.ionic.OtplessPlugin;
`
`
protected void onCreate(Bundle savedInstanceState) {
registerPlugin(OtplessPlugin.class);
super.onCreate(savedInstanceState);
}@Override
public void onBackPressed() {
if (OtplessPlugin.onBackPressed(this)) return;
super.onBackPressed();
}
`* In AndroidManifest file added the intent filter in activity tag of your MainActivity
`
android:host="otpless"
android:scheme= "otpless.your_app_id_in_lowercase"/>
`
Headless API
$3
* Import the OtplessManager
`
import {OtplessManager} from 'otpless-ionic';
`
* In your login component create the instance of OtplessManager.
`
let manager = new OtplessManager()
`* Init the headless sdk in useEffect webhook
`
useEffect(() => {
manager.initHeadless("APP_ID");
manager.setHeadlessCallback(onHeadlessResult);
return () => {
manager.clearListener();
}
}, []);
``
const onHeadlessResult = (data: any) => {
let message: string = JSON.stringify(data);
console.log(message);
}
`#### create phone number request for headless initialization
`
headlessRequest = {
"phone": phoneNumber,
"countryCode": "91"
}
`
* for verification otp field is required
`
headlessRequest = {
"phone": phoneNumber,
"countryCode": "91",
"otp": otp
}
`#### create email request for headless initialization
`
headlessRequest = {
"email": email
}
`
* for verification otp field is required
`
headlessRequest = {
"email": email,
"otp": otp
}
`#### create sso request like whatsapp for headless initialization
`
headlessRequest = {
"channelType": WHATSAPP
}
`
* for verification otp field is required, in case of magic link no verification call is required, it is handled by sdk when user click on link.
`
headlessRequest = {
"channelType": WHATSAPP,
"otp": otp
}
`
#### call startHeadless result is given in onHeadlessResult method
`
await manager.startHeadless(headlessRequest);
`$3
* Go to your application root folder and install pod. Run the below command
`
pod install
`* Add below lines in info.plist file
`
CFBundleURLTypes
CFBundleURLSchemes
CFBundleTypeRole
Editor
CFBundleURLName
otpless
LSApplicationQueriesSchemes
whatsapp
otpless
gootpless
com.otpless.ios.app.otpless
googlegmail
NSAppTransportSecurity
NSAllowsArbitraryLoads
NSExceptionDomains
80.in.safr.sekuramobile.com
NSIncludesSubdomains
NSTemporaryExceptionAllowsInsecureHTTPLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.1
partnerapi.jio.com
NSIncludesSubdomains
NSTemporaryExceptionAllowsInsecureHTTPLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.1
`* Add application method in your AppDelegate
`
import OtplessSDK
`
`
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if (Otpless.sharedInstance.isOtplessDeeplink(url: url)) {
Otpless.sharedInstance.processOtplessDeeplink(url: url)
return true
}
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}
}
`
$3
* In MainActivity register the plugin, before calling super.onCreate.
`
import com.otpless.ionic.OtplessPlugin;
`
`
protected void onCreate(Bundle savedInstanceState) {
registerPlugin(OtplessPlugin.class);
super.onCreate(savedInstanceState);
}@Override
public void onBackPressed() {
if (OtplessPlugin.onBackPressed(this)) return;
super.onBackPressed();
}
`* In AndroidManifest file added the intent filter in activity tag of your MainActivity
`
android:host="otpless"
android:scheme= "otpless.your_app_id_in_lowercase"/>
``