natively 2.13.0 → 2.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +13 -0
- package/natively-frontend.js +6 -1
- package/natively-frontend.min.js +1 -1
- package/natively-frontend.min.mjs +1 -0
- package/natively-frontend.mjs +947 -0
- package/package.json +7 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.formatOnSave": true,
|
|
3
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
4
|
+
"[javascript]": {
|
|
5
|
+
"editor.defaultFormatter": "vscode.typescript-language-features"
|
|
6
|
+
},
|
|
7
|
+
"[html]": {
|
|
8
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
9
|
+
},
|
|
10
|
+
"autominify.enableMinFileJs": false,
|
|
11
|
+
"autominify.enableJsMinification": false,
|
|
12
|
+
}
|
|
13
|
+
|
package/natively-frontend.js
CHANGED
|
@@ -97,6 +97,12 @@ window.natively = {
|
|
|
97
97
|
$agent.natively_logger();
|
|
98
98
|
},
|
|
99
99
|
|
|
100
|
+
// Not available right now
|
|
101
|
+
openConsole: function () {
|
|
102
|
+
window.natively.trigger(undefined, 30, undefined, "app_console");
|
|
103
|
+
|
|
104
|
+
},
|
|
105
|
+
|
|
100
106
|
closeApp: function () {
|
|
101
107
|
window.natively.trigger(undefined, 11, undefined, "app_close");
|
|
102
108
|
},
|
|
@@ -937,4 +943,3 @@ class NativelyAppleSignInService {
|
|
|
937
943
|
function generateID() {
|
|
938
944
|
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
939
945
|
}
|
|
940
|
-
|
package/natively-frontend.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.natively={isDebug:!1,min_app_version:0,app_version:0,injected:!1,observers:[],isIOSApp:window.navigator.userAgent.includes("Natively/iOS"),isAndroidApp:window.navigator.userAgent.includes("Natively/Android"),setDebug:function(isDebug){window.natively.isDebug=isDebug},notify:function(min,current){window.natively.injected=!0,min&&(window.natively.min_app_version=min),current&&(window.natively.app_version=current);const observers=window.natively.observers;for(natively.isDebug&&console.log("[INFO] Notify observers: ",observers.length);observers.length>0;){observers.shift()()}},addObserver:function(fn){window.natively.injected?fn():(window.natively.isDebug&&console.log(`[DEBUG] addObserver: ${fn}`),window.natively.observers.push(fn))},trigger:function(respId,minVersion,callback,method,body){const isTestVersion=window.natively.isDebug;if(window.natively.injected)if(minVersion>window.natively.app_version)isTestVersion&&alert(`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${minVersion}`);else{if(callback){let fullMethodName;fullMethodName=respId?method+"_response_"+respId:method+"_response",window[fullMethodName]=function(resp,err){$agent.response(),err.message&&isTestVersion?alert(`[ERROR] Error message: ${err.message}`):(isTestVersion&&console.log(`[DEBUG] Callback method: ${fullMethodName}, body: ${JSON.stringify(resp)}, respId: ${respId}`),callback(resp))},body?body.response_id=respId:body={response_id:respId}}isTestVersion&&console.log(`[DEBUG] Trigger method: ${method}, body: ${JSON.stringify(body)}`),$agent.trigger(method,body)}else window.natively.addObserver((()=>{window.natively.trigger(respId,minVersion,callback,method,body)}))},openLogger:function(){$agent.natively_logger()},closeApp:function(){window.natively.trigger(void 0,11,void 0,"app_close")},showProgress:function(toggle){window.natively.trigger(void 0,11,void 0,"app_show_progress",{toggle:toggle})},shareImage(image_url){window.natively.trigger(void 0,0,void 0,"share_image",{url:image_url})},shareText(text){window.natively.trigger(void 0,0,void 0,"share_text",{text:text})},shareTextAndImage(text,image_url){window.natively.trigger(void 0,0,void 0,"share_text_and_image",{url:image_url,text:text})},shareFile(file_url){window.natively.trigger(void 0,2,void 0,"share_file",{url:file_url})},openExternalURL(url,external){const params={};params.url=void 0===url?"https://buildnatively.com":url;const isExternal=void 0!==external&&external;params.view=isExternal?"external":"web",window.natively.trigger(void 0,18,void 0,"open_link",params)},openExternalAppIOS(url){window.natively.trigger(void 0,0,void 0,"open_app",{url:url})},openAppSettings(){window.natively.trigger(void 0,0,void 0,"open_appsettings")},hapticPatternIOS(pattern,delay){window.natively.trigger(void 0,7,void 0,"haptic_pattern",{pattern:pattern,delay:delay})},hapticImpactIOS(type){window.natively.trigger(void 0,7,void 0,"haptic_impact",{type:type})},hapticNotificationIOS(type){window.natively.trigger(void 0,7,void 0,"haptic_notification",{type:type})},showAppToast(type,text){const params={};params.text=void 0===text?"":text,params.type=void 0===type?"DEFAULT":type,window.natively.trigger(void 0,0,void 0,"show_toast",params)},showAppBanner(type,title,description){const params={};params.type=void 0===type?"INFO":type,params.title=void 0===title?"":title,params.description=void 0===description?"":description,window.natively.trigger(void 0,0,void 0,"show_banner",params)},requestAppReview(){window.natively.trigger(void 0,0,void 0,"request_review")},setAppBackgroundColor(color){const params={color:color};window.natively.trigger(void 0,1,void 0,"app_background",params)},setAppProgressColor(color){const params={color:color};window.natively.trigger(void 0,1,void 0,"app_progress",params)},setAppSwipeNavigationIOS(toggle){const params={toggle:toggle};window.natively.trigger(void 0,1,void 0,"app_navigation",params)},setAppPullToRefresh(toggle){const params={toggle:toggle};window.natively.trigger(void 0,1,void 0,"app_pull",params)},setAppOrientation(orientation){const params={orientation:orientation};window.natively.trigger(void 0,3,void 0,"app_orientation",params)},setAppStatusBarStyleIOS(style){const params={style:style};window.natively.trigger(void 0,2,void 0,"status_bar_style",params)},hideLoadingScreen(){const params={show_loader:!1,auto_hide:!0};window.natively.trigger(void 0,17,void 0,"loading_screen",params)},showLoadingScreen(autoHide){const params={show_loader:!0,auto_hide:void 0!==autoHide&&autoHide};window.natively.trigger(void 0,17,void 0,"loading_screen",params)},async sendPushNotification(appId,payload,player_ids,isPreview){const filtered=player_ids.filter((id=>id.length>0));let notification={app_id:isPreview?"be83022a-1d08-45d0-a07a-0c3655666e17":appId,include_player_ids:[...new Set(filtered)]};payload.template_id?notification.template_id=payload.template_id:(notification.headings={},notification.headings.en=payload.title||"Empty Title",notification.contents={},notification.contents.en=payload.message||"Empty Message",payload.subtitle&&(notification.subtitle={},notification.subtitle.en=payload.subtitle),payload.redirect_url&&(notification.url=payload.redirect_url));const options={method:"POST",headers:{"Content-type":"application/json"},body:JSON.stringify(notification)};return await fetch("https://onesignal.com/api/v1/notifications",options)}},window.natively.addObserver((()=>window.natively.trigger(void 0,0,(resp=>{window.natively.min_app_version=resp.minSDKVersion,window.natively.app_version=resp.sdkVersion}),"app_info",{})));class NativelyInfo{constructor(){const id=generateID();this.browserInfo=function(){return{isNativeApp:"undefined"!=typeof $agent,isIOSApp:window.navigator.userAgent.includes("Natively/iOS"),isAndroidApp:window.navigator.userAgent.includes("Natively/Android")}},this.getAppInfo=function(app_info_callback){window.natively.trigger(id,0,app_info_callback,"app_info")},this.connectivity=function(connectivity_callback){window.natively.trigger(void 0,0,connectivity_callback,"connectivity")},this.app_state=function(app_state_callback){window.natively.trigger(void 0,19,app_state_callback,"app_state")}}}class NativelyClipboard{constructor(){const id=generateID();this.copy=function(text){window.natively.trigger(void 0,11,void 0,"clipboard_copy",{text:text})},this.paste=function(paste_callback){window.natively.trigger(id,11,paste_callback,"clipboard_paste")}}}class NativelyPagesCache{constructor(){const id=generateID();this.currentPageCached=function(current_page_cached_callback){window.natively.trigger(id,4,current_page_cached_callback,"current_page_cached")},this.storeCurrentPage=function(store_current_page_callback){window.natively.trigger(id,4,store_current_page_callback,"store_current_page")},this.resetCurrentPage=function(reset_current_page_callback){window.natively.trigger(id,4,reset_current_page_callback,"reset_current_page")},this.resetAll=function(reset_all_callback){window.natively.trigger(id,4,reset_all_callback,"reset_all")}}}class NativelyNotifications{constructor(){const id=generateID();this.getOneSignalId=function(onesignal_playerid_callback){window.natively.trigger(id,0,onesignal_playerid_callback,"onesignal_playerid")},this.requestPermission=function(fallbackToSettings,push_register_callback){window.natively.trigger(id,0,push_register_callback,"push_register",{fallbackToSettings:fallbackToSettings})},this.getPermissionStatus=function(push_permission_callback){window.natively.trigger(id,0,push_permission_callback,"push_permission")}}}class NativelyGeolocation{constructor(){const id=generateID();this.getUserGeolocation=function(distance,geolocation_callback){window.natively.trigger(id,0,geolocation_callback,"geolocation",{distance:distance})},this.requestPermission=function(geo_register_callback){window.natively.trigger(id,0,geo_register_callback,"geo_register")},this.getPermissionStatus=function(geo_permission_callback){window.natively.trigger(id,0,geo_permission_callback,"geo_permission")}}}class NativelyLocation{constructor(){const id=generateID();this.current=function(minAccuracyIOS,accuracyTypeIOS,priority_android,location_callback){window.natively.trigger(id,12,location_callback,"location_current",{minAccuracy:minAccuracyIOS,accuracyType:accuracyTypeIOS,priority:priority_android})},this.permission=function(location_permission_callback){window.natively.trigger(id,6,location_permission_callback,"location_permission")},this.start=function(interval,minAccuracyIOS,accuracyTypeIOS,priority_android,location_callback){window.natively.trigger(id,12,location_callback,"location_start",{minAccuracy:minAccuracyIOS,accuracyType:accuracyTypeIOS,priority:priority_android,interval:interval})},this.stop=function(){window.natively.trigger(id,3,void 0,"location_stop",{})},this.startBackground=function(interval,minAccuracyIOS,accuracyTypeIOS,priority_android,responseIdentifier,location_bg_callback){const params={};params.identifier=void 0===responseIdentifier?"empty":responseIdentifier,params.interval=void 0===interval?6e4:interval,params.minAccuracy=void 0===minAccuracyIOS?50:minAccuracyIOS,params.accuracyType=void 0===accuracyTypeIOS?"Best":accuracyTypeIOS,params.priority=void 0===priority_android?"BALANCED":priority_android,window.natively.trigger(id,12,location_bg_callback,"location_start_bg",params)},this.statusBackground=function(location_bg_status_callback){window.natively.trigger(id,20,location_bg_status_callback,"location_status_bg",{})},this.stopBackground=function(location_bg_callback){window.natively.trigger(id,4,location_bg_callback,"location_stop_bg",{})}}}class NativelyMessage{constructor(){const id=generateID();this.sendSMS=function(body,recipient,send_sms_callback){const params={};params.body=void 0===body?"":body,params.recipient=void 0===recipient?"":recipient,window.natively.trigger(id,0,send_sms_callback,"send_sms",params)},this.sendEmail=function(subject,body,recipient,send_email_callback){const params={};params.subject=void 0===subject?"":subject,params.body=void 0===body?"":body,params.recipient=void 0===recipient?"":recipient,window.natively.trigger(id,0,send_email_callback,"send_email",params)}}}class NativelyStorage{constructor(){const id=generateID();this.setStorageValue=function(key,value){window.natively.trigger(id,0,void 0,"set_storage_value",{key:key,value:value})},this.getStorageValue=function(key,get_storage_value_callback){window.natively.trigger(id,0,get_storage_value_callback,"get_storage_value",{key:key})},this.removeStorageValue=function(key){window.natively.trigger(id,0,void 0,"remove_storage_value",{key:key})},this.resetStorage=function(){window.natively.trigger(id,0,void 0,"reset_storage")}}}class NativelyBiometrics{constructor(allowPass){this.allowPass=allowPass;const id=generateID();this.checkBiometricsSupport=function(biometrics_support_callback){window.natively.trigger(id,0,biometrics_support_callback,"biometrics_support",{allowPass:allowPass})},this.checkCredentials=function(biometrics_has_credentials_callback){window.natively.trigger(id,0,biometrics_has_credentials_callback,"biometrics_has_credentials")},this.verifyUserIdentify=function(biometrics_verify_callback){window.natively.trigger(id,0,biometrics_verify_callback,"biometrics_verify",{allowPass:allowPass})},this.getUserCredentials=function(biometrics_auth_callback){window.natively.trigger(id,0,biometrics_auth_callback,"biometrics_auth",{allowPass:allowPass})},this.removeUserCredentials=function(biometrics_remove_credentials_callback){window.natively.trigger(id,0,biometrics_remove_credentials_callback,"biometrics_remove_credentials")},this.saveUserCredentials=function(login,password,biometrics_auth_callback){window.natively.trigger(id,0,biometrics_auth_callback,"biometrics_auth",{allowPass:allowPass,login:login,password:password})}}}class NativelyDatePicker{constructor(){const id=generateID();this.showDatePicker=function(title,description,type,style,datepicker_callback){let params={};params.type=void 0===type?"DATE":type,params.style=void 0===style?"LIGHT":style,params.title=void 0===title?"":title,params.description=void 0===description?"":description,window.natively.trigger(id,0,datepicker_callback,"datepicker",params)}}}class NativelyCamera{constructor(){const id=generateID();this.showCamera=function(type,quality,camera,open_camera_callback){let params={};params.type=void 0===type?"photo":type,params.quality=void 0===quality?"high":quality,params.camera=void 0===camera?"BACK":camera,window.natively.trigger(id,2,open_camera_callback,"open_camera",params)}}}class NativelyHealth{constructor(){const id=generateID();this.available=function(available_callback){window.natively.trigger(id,10,available_callback,"health_available",{})},this.requestAuthorization=function(write_data_types,read_data_types,request_callback){window.natively.trigger(id,10,request_callback,"health_register",{write_data_types:write_data_types,read_data_types:read_data_types})},this.permissionStatus=function(data_type,callback){window.natively.trigger(id,10,callback,"health_permission",{data_type:data_type})},this.getAllCharacteristics=function(callback){window.natively.trigger(id,10,callback,"health_get_all_characteristics",{})},this.getStatisticQuantity=function(data_type,interval,start_date,end_date,callback){const obj={data_type:data_type,interval:interval};void 0!==start_date&&(obj.start_date=start_date.getTime()),void 0!==end_date&&(obj.end_date=end_date.getTime()),window.natively.trigger(id,10,callback,"health_get_statistic_quantity",obj)},this.getDailySleepAnalysis=function(start_date,end_date,limit,callback){const obj={limit:limit||100};void 0!==start_date&&(obj.start_date=start_date.getTime()),void 0!==end_date&&(obj.end_date=end_date.getTime()),window.natively.trigger(id,10,callback,"health_get_daily_sleep_analysis",obj)},this.getWorkouts=function(start_date,end_date,limit,callback){const obj={limit:limit||100};void 0!==start_date&&(obj.start_date=start_date.getTime()),void 0!==end_date&&(obj.end_date=end_date.getTime()),window.natively.trigger(id,21,callback,"health_get_workouts",obj)},this.getActivitySummary=function(start_date,end_date,callback){const obj={};void 0!==start_date&&(obj.start_date=start_date.getTime()),void 0!==end_date&&(obj.end_date=end_date.getTime()),window.natively.trigger(id,10,callback,"health_get_activity_summary",obj)}}}class NativelyScanner{constructor(){const id=generateID();this.showScanner=function(open_scanner_callback){window.natively.trigger(id,2,open_scanner_callback,"open_scanner",{})}}}class NativelyPurchases{constructor(){const id=generateID();this.login=function(login,customerEmail,login_callback){const email=void 0===customerEmail?"":customerEmail;window.natively.trigger(id,3,login_callback,"purchases_login",{login:login,email:email})},this.logout=function(logout_callback){window.natively.trigger(id,3,logout_callback,"purchases_logout",{})},this.customerId=function(customer_id_callback){window.natively.trigger(id,3,customer_id_callback,"purchases_customerid",{})},this.restore=function(restore_callback){window.natively.trigger(id,10,restore_callback,"purchases_restore",{})},this.purchasePackage=function(packageId,purchase_callback){window.natively.trigger(id,3,purchase_callback,"purchases_package",{packageId:packageId})},this.packagePrice=function(packageId,purchase_callback){window.natively.trigger(id,8,purchase_callback,"purchases_price",{packageId:packageId})}}}class NativelyContacts{constructor(){const id=generateID();this.getAllContacts=function(contacts_all_callback){window.natively.trigger(id,3,contacts_all_callback,"contacts_all",{})},this.createContact=function(firstName,lastName,email,phone,contacts_save_callback){let params={firstName:firstName};params.lastName=void 0===lastName?"":lastName,params.email=void 0===email?"":email,params.phone=void 0===phone?"":phone,window.natively.trigger(id,3,contacts_save_callback,"contacts_save",params)}}}class NativelyMediaPicker{constructor(){const id=generateID();this.showMediaPicker=function(mediapicker_callback){window.natively.trigger(id,8,mediapicker_callback,"mediapicker",{})}}}class NativelyAudioRecorder{constructor(){const id=generateID();this.showRecorder=function(max_duration,record_callback){let params={};params.max_duration=void 0===max_duration?0:max_duration,window.natively.trigger(id,13,record_callback,"record_start",params)}}}class NativelyAdmobBanner{constructor(config={iOSUnitId:"ca-app-pub-3940256099942544/2934735716",androidUnitId:"ca-app-pub-3940256099942544/6300978111",position:"BOTTOM",sizeType:"AUTO",custom_width:320,custom_height:50},setup_callback=void 0,preload_ad=!1,preload_callback=void 0,show_ad=!1,show_callback=void 0){const id=generateID(),params={};window.natively.isAndroidApp?params.unitId=void 0===config.androidUnitId?"ca-app-pub-3940256099942544/6300978111":config.androidUnitId:window.natively.isIOSApp&&(params.unitId=void 0===config.iOSUnitId?"ca-app-pub-3940256099942544/2934735716":config.iOSUnitId),params.position=void 0===config.position?"BOTTOM":config.position,params.sizeType=void 0===config.sizeType?"AUTO":config.sizeType,params.width=void 0===config.custom_width?320:config.width,params.height=void 0===config.custom_height?50:config.height,window.natively.trigger(id,14,(function(resp){void 0!==setup_callback&&setup_callback(resp),preload_ad&&window.natively.trigger(id,14,(function(resp){void 0!==preload_callback&&preload_callback(resp),show_ad&&window.natively.trigger(id,14,show_callback,"bannerad_show",{})}),"bannerad_load",{})}),"bannerad_setup",params),this.loadAd=function(callback){window.natively.trigger(id,14,callback,"bannerad_load",{})},this.showBanner=function(callback){window.natively.trigger(id,14,callback,"bannerad_show",{})},this.hideBanner=function(callback){window.natively.trigger(id,14,callback,"bannerad_hide",{})},this.bannerIsReady=function(callback){window.natively.trigger(id,14,callback,"bannerad_ready",{})},this.bannerIsVisible=function(callback){window.natively.trigger(id,14,callback,"bannerad_visible",{})}}}class NativelyAdmobInterstitial{constructor(iOSUnitId="ca-app-pub-3940256099942544/4411468910",androidUnitId="ca-app-pub-3940256099942544/1033173712",setup_callback=void 0,auto_ad_reload=!1,auto_ad_reload_callback=void 0){const id=generateID();let unitId;window.natively.isAndroidApp?unitId=void 0===androidUnitId?"ca-app-pub-3940256099942544/1033173712":androidUnitId:window.natively.isIOSApp&&(unitId=void 0===iOSUnitId?"ca-app-pub-3940256099942544/4411468910":iOSUnitId),this.loadAd=function(callback){const params={};params.unitId=void 0===unitId?"ca-app-pub-3940256099942544/4411468910":unitId,window.natively.trigger(id,14,callback,"interstitialad_setup",params)},this.showInterstitialAd=function(callback){window.natively.trigger(id,14,(function(resp){if(callback(resp),"DID_DISMISS_AD"===resp.event&&auto_ad_reload){const params={};params.unitId=unitId,setTimeout((()=>{window.natively.trigger(id,14,auto_ad_reload_callback,"interstitialad_setup",params)}),500)}}),"interstitialad_show",{})},this.interstitialIsReady=function(callback){window.natively.trigger(id,14,callback,"interstitialad_ready",{})},this.loadAd(setup_callback)}}class NativelyNFCService{constructor(readAlertMessage,writeAlertMessage,readDetectedMessage,writeDetectedMessage){const id=generateID();this.readAlertMessage=readAlertMessage,this.writeAlertMessage=writeAlertMessage,this.readDetectedMessage=readDetectedMessage,this.writeDetectedMessage=writeDetectedMessage,this.read=function(callback){let params={};params.alertMessage=void 0===this.readAlertMessage?"please set readAlertMessage":this.readAlertMessage,params.detectedMessage=void 0===this.readDetectedMessage?"readDetectedMessage":this.readDetectedMessage,window.natively.trigger(id,15,callback,"nfc_read",params)},this.write=function(recordId,recordData,callback){let params={};params.alertMessage=void 0===this.writeAlertMessage?"please set writeAlertMessage":this.writeAlertMessage,params.detectedMessage=void 0===this.writeDetectedMessage?"please set writeDetectedMessage":this.writeDetectedMessage,params.recordData=void 0===recordData?"please set recordData":recordData,params.recordId=void 0===recordId?"please set recordId":recordId,window.natively.trigger(id,15,callback,"nfc_write",params)},this.available=function(callback){window.natively.trigger(id,15,callback,"nfc_available",{})}}}class NativelyAppleSignInService{constructor(){const id=generateID();this.signin=function(callback){window.natively.trigger(id,16,callback,"apple_signin",{})}}}function generateID(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}
|
|
1
|
+
window.natively={isDebug:false,min_app_version:0,app_version:0,injected:false,observers:[],isIOSApp:window.navigator.userAgent.includes("Natively/iOS"),isAndroidApp:window.navigator.userAgent.includes("Natively/Android"),setDebug:function(isDebug){window.natively.isDebug=isDebug},notify:function(min,current){window.natively.injected=true;if(min){window.natively.min_app_version=min}if(current){window.natively.app_version=current}const observers=window.natively.observers;if(natively.isDebug){console.log("[INFO] Notify observers: ",observers.length)}while(observers.length>0){const observer=observers.shift();observer()}},addObserver:function(fn){if(window.natively.injected){fn()}else{if(window.natively.isDebug){console.log(`[DEBUG] addObserver: ${fn}`)}window.natively.observers.push(fn)}},trigger:function(respId,minVersion,callback,method,body){const isTestVersion=window.natively.isDebug;if(!window.natively.injected){window.natively.addObserver((()=>{window.natively.trigger(respId,minVersion,callback,method,body)}));return}if(minVersion>window.natively.app_version){if(isTestVersion){alert(`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${minVersion}`)}return}if(callback){let fullMethodName;if(respId){fullMethodName=method+"_response"+"_"+respId}else{fullMethodName=method+"_response"}window[fullMethodName]=function(resp,err){$agent.response();if(err.message&&isTestVersion){alert(`[ERROR] Error message: ${err.message}`);return}if(isTestVersion){console.log(`[DEBUG] Callback method: ${fullMethodName}, body: ${JSON.stringify(resp)}, respId: ${respId}`)}callback(resp)};if(body){body.response_id=respId}else{body={response_id:respId}}}if(isTestVersion){console.log(`[DEBUG] Trigger method: ${method}, body: ${JSON.stringify(body)}`)}$agent.trigger(method,body)},openLogger:function(){$agent.natively_logger()},openConsole:function(){window.natively.trigger(undefined,30,undefined,"app_console")},closeApp:function(){window.natively.trigger(undefined,11,undefined,"app_close")},showProgress:function(toggle){window.natively.trigger(undefined,11,undefined,"app_show_progress",{toggle:toggle})},shareImage(image_url){window.natively.trigger(undefined,0,undefined,"share_image",{url:image_url})},shareText(text){window.natively.trigger(undefined,0,undefined,"share_text",{text:text})},shareTextAndImage(text,image_url){window.natively.trigger(undefined,0,undefined,"share_text_and_image",{url:image_url,text:text})},shareFile(file_url){window.natively.trigger(undefined,2,undefined,"share_file",{url:file_url})},openExternalURL(url,external){const params={};params.url=typeof url==="undefined"?"https://buildnatively.com":url;const isExternal=typeof external==="undefined"?false:external;params.view=isExternal?"external":"web";window.natively.trigger(undefined,18,undefined,"open_link",params)},openExternalAppIOS(url){window.natively.trigger(undefined,0,undefined,"open_app",{url:url})},openAppSettings(){window.natively.trigger(undefined,0,undefined,"open_appsettings")},hapticPatternIOS(pattern,delay){window.natively.trigger(undefined,7,undefined,"haptic_pattern",{pattern:pattern,delay:delay})},hapticImpactIOS(type){window.natively.trigger(undefined,7,undefined,"haptic_impact",{type:type})},hapticNotificationIOS(type){window.natively.trigger(undefined,7,undefined,"haptic_notification",{type:type})},showAppToast(type,text){const params={};params.text=typeof text==="undefined"?"":text;params.type=typeof type==="undefined"?"DEFAULT":type;window.natively.trigger(undefined,0,undefined,"show_toast",params)},showAppBanner(type,title,description){const params={};params.type=typeof type==="undefined"?"INFO":type;params.title=typeof title==="undefined"?"":title;params.description=typeof description==="undefined"?"":description;window.natively.trigger(undefined,0,undefined,"show_banner",params)},requestAppReview(){window.natively.trigger(undefined,0,undefined,"request_review")},setAppBackgroundColor(color){const params={color:color};window.natively.trigger(undefined,1,undefined,"app_background",params)},setAppProgressColor(color){const params={color:color};window.natively.trigger(undefined,1,undefined,"app_progress",params)},setAppSwipeNavigationIOS(toggle){const params={toggle:toggle};window.natively.trigger(undefined,1,undefined,"app_navigation",params)},setAppPullToRefresh(toggle){const params={toggle:toggle};window.natively.trigger(undefined,1,undefined,"app_pull",params)},setAppOrientation(orientation){const params={orientation:orientation};window.natively.trigger(undefined,3,undefined,"app_orientation",params)},setAppStatusBarStyleIOS(style){const params={style:style};window.natively.trigger(undefined,2,undefined,"status_bar_style",params)},hideLoadingScreen(){const show_loader=false;const auto_hide=true;const params={show_loader:show_loader,auto_hide:auto_hide};window.natively.trigger(undefined,17,undefined,"loading_screen",params)},showLoadingScreen(autoHide){const show_loader=true;const auto_hide=typeof autoHide==="undefined"?false:autoHide;const params={show_loader:show_loader,auto_hide:auto_hide};window.natively.trigger(undefined,17,undefined,"loading_screen",params)},async sendPushNotification(appId,payload,player_ids,isPreview){const filtered=player_ids.filter((id=>id.length>0));const include_player_ids=[...new Set(filtered)];let notification={app_id:isPreview?"be83022a-1d08-45d0-a07a-0c3655666e17":appId,include_player_ids:include_player_ids};if(payload.template_id){notification.template_id=payload.template_id}else{notification.headings={};notification.headings.en=payload.title||"Empty Title";notification.contents={};notification.contents.en=payload.message||"Empty Message";if(payload.subtitle){notification.subtitle={};notification.subtitle.en=payload.subtitle}if(payload.redirect_url){notification.url=payload.redirect_url}}const options={method:"POST",headers:{"Content-type":"application/json"},body:JSON.stringify(notification)};return await fetch("https://onesignal.com/api/v1/notifications",options)}};window.natively.addObserver((()=>window.natively.trigger(undefined,0,(resp=>{window.natively.min_app_version=resp.minSDKVersion;window.natively.app_version=resp.sdkVersion}),"app_info",{})));class NativelyInfo{constructor(){const id=generateID();this.browserInfo=function(){const isNativeApp=typeof $agent!=="undefined";const isIOSApp=window.navigator.userAgent.includes("Natively/iOS");const isAndroidApp=window.navigator.userAgent.includes("Natively/Android");return{isNativeApp:isNativeApp,isIOSApp:isIOSApp,isAndroidApp:isAndroidApp}};this.getAppInfo=function(app_info_callback){window.natively.trigger(id,0,app_info_callback,"app_info")};this.connectivity=function(connectivity_callback){window.natively.trigger(undefined,0,connectivity_callback,"connectivity")};this.app_state=function(app_state_callback){window.natively.trigger(undefined,19,app_state_callback,"app_state")}}}class NativelyClipboard{constructor(){const id=generateID();this.copy=function(text){window.natively.trigger(undefined,11,undefined,"clipboard_copy",{text:text})};this.paste=function(paste_callback){window.natively.trigger(id,11,paste_callback,"clipboard_paste")}}}class NativelyPagesCache{constructor(){const id=generateID();this.currentPageCached=function(current_page_cached_callback){window.natively.trigger(id,4,current_page_cached_callback,"current_page_cached")};this.storeCurrentPage=function(store_current_page_callback){window.natively.trigger(id,4,store_current_page_callback,"store_current_page")};this.resetCurrentPage=function(reset_current_page_callback){window.natively.trigger(id,4,reset_current_page_callback,"reset_current_page")};this.resetAll=function(reset_all_callback){window.natively.trigger(id,4,reset_all_callback,"reset_all")}}}class NativelyNotifications{constructor(){const id=generateID();this.getOneSignalId=function(onesignal_playerid_callback){window.natively.trigger(id,0,onesignal_playerid_callback,"onesignal_playerid")};this.requestPermission=function(fallbackToSettings,push_register_callback){window.natively.trigger(id,0,push_register_callback,"push_register",{fallbackToSettings:fallbackToSettings})};this.getPermissionStatus=function(push_permission_callback){window.natively.trigger(id,0,push_permission_callback,"push_permission")}}}class NativelyGeolocation{constructor(){const id=generateID();this.getUserGeolocation=function(distance,geolocation_callback){window.natively.trigger(id,0,geolocation_callback,"geolocation",{distance:distance})};this.requestPermission=function(geo_register_callback){window.natively.trigger(id,0,geo_register_callback,"geo_register")};this.getPermissionStatus=function(geo_permission_callback){window.natively.trigger(id,0,geo_permission_callback,"geo_permission")}}}class NativelyLocation{constructor(){const id=generateID();this.current=function(minAccuracyIOS,accuracyTypeIOS,priority_android,location_callback){window.natively.trigger(id,12,location_callback,"location_current",{minAccuracy:minAccuracyIOS,accuracyType:accuracyTypeIOS,priority:priority_android})};this.permission=function(location_permission_callback){window.natively.trigger(id,6,location_permission_callback,"location_permission")};this.start=function(interval,minAccuracyIOS,accuracyTypeIOS,priority_android,location_callback){window.natively.trigger(id,12,location_callback,"location_start",{minAccuracy:minAccuracyIOS,accuracyType:accuracyTypeIOS,priority:priority_android,interval:interval})};this.stop=function(){window.natively.trigger(id,3,undefined,"location_stop",{})};this.startBackground=function(interval,minAccuracyIOS,accuracyTypeIOS,priority_android,responseIdentifier,location_bg_callback){const params={};params.identifier=typeof responseIdentifier==="undefined"?"empty":responseIdentifier;params.interval=typeof interval==="undefined"?1e3*60:interval;params.minAccuracy=typeof minAccuracyIOS==="undefined"?50:minAccuracyIOS;params.accuracyType=typeof accuracyTypeIOS==="undefined"?"Best":accuracyTypeIOS;params.priority=typeof priority_android==="undefined"?"BALANCED":priority_android;window.natively.trigger(id,12,location_bg_callback,"location_start_bg",params)};this.statusBackground=function(location_bg_status_callback){window.natively.trigger(id,20,location_bg_status_callback,"location_status_bg",{})};this.stopBackground=function(location_bg_callback){window.natively.trigger(id,4,location_bg_callback,"location_stop_bg",{})}}}class NativelyMessage{constructor(){const id=generateID();this.sendSMS=function(body,recipient,send_sms_callback){const params={};params.body=typeof body==="undefined"?"":body;params.recipient=typeof recipient==="undefined"?"":recipient;window.natively.trigger(id,0,send_sms_callback,"send_sms",params)};this.sendEmail=function(subject,body,recipient,send_email_callback){const params={};params.subject=typeof subject==="undefined"?"":subject;params.body=typeof body==="undefined"?"":body;params.recipient=typeof recipient==="undefined"?"":recipient;window.natively.trigger(id,0,send_email_callback,"send_email",params)}}}class NativelyStorage{constructor(){const id=generateID();this.setStorageValue=function(key,value){window.natively.trigger(id,0,undefined,"set_storage_value",{key:key,value:value})};this.getStorageValue=function(key,get_storage_value_callback){window.natively.trigger(id,0,get_storage_value_callback,"get_storage_value",{key:key})};this.removeStorageValue=function(key){window.natively.trigger(id,0,undefined,"remove_storage_value",{key:key})};this.resetStorage=function(){window.natively.trigger(id,0,undefined,"reset_storage")}}}class NativelyBiometrics{constructor(allowPass){this.allowPass=allowPass;const id=generateID();this.checkBiometricsSupport=function(biometrics_support_callback){window.natively.trigger(id,0,biometrics_support_callback,"biometrics_support",{allowPass:allowPass})};this.checkCredentials=function(biometrics_has_credentials_callback){window.natively.trigger(id,0,biometrics_has_credentials_callback,"biometrics_has_credentials")};this.verifyUserIdentify=function(biometrics_verify_callback){window.natively.trigger(id,0,biometrics_verify_callback,"biometrics_verify",{allowPass:allowPass})};this.getUserCredentials=function(biometrics_auth_callback){window.natively.trigger(id,0,biometrics_auth_callback,"biometrics_auth",{allowPass:allowPass})};this.removeUserCredentials=function(biometrics_remove_credentials_callback){window.natively.trigger(id,0,biometrics_remove_credentials_callback,"biometrics_remove_credentials")};this.saveUserCredentials=function(login,password,biometrics_auth_callback){window.natively.trigger(id,0,biometrics_auth_callback,"biometrics_auth",{allowPass:allowPass,login:login,password:password})}}}class NativelyDatePicker{constructor(){const id=generateID();this.showDatePicker=function(title,description,type,style,datepicker_callback){let params={};params.type=typeof type==="undefined"?"DATE":type;params.style=typeof style==="undefined"?"LIGHT":style;params.title=typeof title==="undefined"?"":title;params.description=typeof description==="undefined"?"":description;window.natively.trigger(id,0,datepicker_callback,"datepicker",params)}}}class NativelyCamera{constructor(){const id=generateID();this.showCamera=function(type,quality,camera,open_camera_callback){let params={};params.type=typeof type==="undefined"?"photo":type;params.quality=typeof quality==="undefined"?"high":quality;params.camera=typeof camera==="undefined"?"BACK":camera;window.natively.trigger(id,2,open_camera_callback,"open_camera",params)}}}class NativelyHealth{constructor(){const id=generateID();this.available=function(available_callback){window.natively.trigger(id,10,available_callback,"health_available",{})};this.requestAuthorization=function(write_data_types,read_data_types,request_callback){window.natively.trigger(id,10,request_callback,"health_register",{write_data_types:write_data_types,read_data_types:read_data_types})};this.permissionStatus=function(data_type,callback){window.natively.trigger(id,10,callback,"health_permission",{data_type:data_type})};this.getAllCharacteristics=function(callback){window.natively.trigger(id,10,callback,"health_get_all_characteristics",{})};this.getStatisticQuantity=function(data_type,interval,start_date,end_date,callback){const obj={data_type:data_type,interval:interval};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,10,callback,"health_get_statistic_quantity",obj)};this.getDailySleepAnalysis=function(start_date,end_date,limit,callback){const obj={limit:limit||100};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,10,callback,"health_get_daily_sleep_analysis",obj)};this.getWorkouts=function(start_date,end_date,limit,callback){const obj={limit:limit||100};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,21,callback,"health_get_workouts",obj)};this.getActivitySummary=function(start_date,end_date,callback){const obj={};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,10,callback,"health_get_activity_summary",obj)}}}class NativelyScanner{constructor(){const id=generateID();this.showScanner=function(open_scanner_callback){window.natively.trigger(id,2,open_scanner_callback,"open_scanner",{})}}}class NativelyPurchases{constructor(){const id=generateID();this.login=function(login,customerEmail,login_callback){const email=typeof customerEmail==="undefined"?"":customerEmail;window.natively.trigger(id,3,login_callback,"purchases_login",{login:login,email:email})};this.logout=function(logout_callback){window.natively.trigger(id,3,logout_callback,"purchases_logout",{})};this.customerId=function(customer_id_callback){window.natively.trigger(id,3,customer_id_callback,"purchases_customerid",{})};this.restore=function(restore_callback){window.natively.trigger(id,10,restore_callback,"purchases_restore",{})};this.purchasePackage=function(packageId,purchase_callback){window.natively.trigger(id,3,purchase_callback,"purchases_package",{packageId:packageId})};this.packagePrice=function(packageId,purchase_callback){window.natively.trigger(id,8,purchase_callback,"purchases_price",{packageId:packageId})}}}class NativelyContacts{constructor(){const id=generateID();this.getAllContacts=function(contacts_all_callback){window.natively.trigger(id,3,contacts_all_callback,"contacts_all",{})};this.createContact=function(firstName,lastName,email,phone,contacts_save_callback){let params={firstName:firstName};params.lastName=typeof lastName==="undefined"?"":lastName;params.email=typeof email==="undefined"?"":email;params.phone=typeof phone==="undefined"?"":phone;window.natively.trigger(id,3,contacts_save_callback,"contacts_save",params)}}}class NativelyMediaPicker{constructor(){const id=generateID();this.showMediaPicker=function(mediapicker_callback){window.natively.trigger(id,8,mediapicker_callback,"mediapicker",{})}}}class NativelyAudioRecorder{constructor(){const id=generateID();this.showRecorder=function(max_duration,record_callback){let params={};params.max_duration=typeof max_duration==="undefined"?0:max_duration;window.natively.trigger(id,13,record_callback,"record_start",params)}}}class NativelyAdmobBanner{constructor(config={iOSUnitId:"ca-app-pub-3940256099942544/2934735716",androidUnitId:"ca-app-pub-3940256099942544/6300978111",position:"BOTTOM",sizeType:"AUTO",custom_width:320,custom_height:50},setup_callback=undefined,preload_ad=false,preload_callback=undefined,show_ad=false,show_callback=undefined){const id=generateID();const params={};if(window.natively.isAndroidApp){params.unitId=typeof config.androidUnitId==="undefined"?"ca-app-pub-3940256099942544/6300978111":config.androidUnitId}else if(window.natively.isIOSApp){params.unitId=typeof config.iOSUnitId==="undefined"?"ca-app-pub-3940256099942544/2934735716":config.iOSUnitId}params.position=typeof config.position==="undefined"?"BOTTOM":config.position;params.sizeType=typeof config.sizeType==="undefined"?"AUTO":config.sizeType;params.width=typeof config.custom_width==="undefined"?320:config.width;params.height=typeof config.custom_height==="undefined"?50:config.height;window.natively.trigger(id,14,(function(resp){if(typeof setup_callback!=="undefined"){setup_callback(resp)}if(preload_ad){window.natively.trigger(id,14,(function(resp){if(typeof preload_callback!=="undefined"){preload_callback(resp)}if(show_ad){window.natively.trigger(id,14,show_callback,"bannerad_show",{})}}),"bannerad_load",{})}}),"bannerad_setup",params);this.loadAd=function(callback){window.natively.trigger(id,14,callback,"bannerad_load",{})};this.showBanner=function(callback){window.natively.trigger(id,14,callback,"bannerad_show",{})};this.hideBanner=function(callback){window.natively.trigger(id,14,callback,"bannerad_hide",{})};this.bannerIsReady=function(callback){window.natively.trigger(id,14,callback,"bannerad_ready",{})};this.bannerIsVisible=function(callback){window.natively.trigger(id,14,callback,"bannerad_visible",{})}}}class NativelyAdmobInterstitial{constructor(iOSUnitId="ca-app-pub-3940256099942544/4411468910",androidUnitId="ca-app-pub-3940256099942544/1033173712",setup_callback=undefined,auto_ad_reload=false,auto_ad_reload_callback=undefined){const id=generateID();let unitId;if(window.natively.isAndroidApp){unitId=typeof androidUnitId==="undefined"?"ca-app-pub-3940256099942544/1033173712":androidUnitId}else if(window.natively.isIOSApp){unitId=typeof iOSUnitId==="undefined"?"ca-app-pub-3940256099942544/4411468910":iOSUnitId}this.loadAd=function(callback){const params={};params.unitId=typeof unitId==="undefined"?"ca-app-pub-3940256099942544/4411468910":unitId;window.natively.trigger(id,14,callback,"interstitialad_setup",params)};this.showInterstitialAd=function(callback){window.natively.trigger(id,14,(function(resp){callback(resp);if(resp.event==="DID_DISMISS_AD"&&auto_ad_reload){const params={};params.unitId=unitId;setTimeout((()=>{window.natively.trigger(id,14,auto_ad_reload_callback,"interstitialad_setup",params)}),500)}}),"interstitialad_show",{})};this.interstitialIsReady=function(callback){window.natively.trigger(id,14,callback,"interstitialad_ready",{})};this.loadAd(setup_callback)}}class NativelyNFCService{constructor(readAlertMessage,writeAlertMessage,readDetectedMessage,writeDetectedMessage){const id=generateID();this.readAlertMessage=readAlertMessage;this.writeAlertMessage=writeAlertMessage;this.readDetectedMessage=readDetectedMessage;this.writeDetectedMessage=writeDetectedMessage;this.read=function(callback){let params={};params.alertMessage=typeof this.readAlertMessage==="undefined"?"please set readAlertMessage":this.readAlertMessage;params.detectedMessage=typeof this.readDetectedMessage==="undefined"?"readDetectedMessage":this.readDetectedMessage;window.natively.trigger(id,15,callback,"nfc_read",params)};this.write=function(recordId,recordData,callback){let params={};params.alertMessage=typeof this.writeAlertMessage==="undefined"?"please set writeAlertMessage":this.writeAlertMessage;params.detectedMessage=typeof this.writeDetectedMessage==="undefined"?"please set writeDetectedMessage":this.writeDetectedMessage;params.recordData=typeof recordData==="undefined"?"please set recordData":recordData;params.recordId=typeof recordId==="undefined"?"please set recordId":recordId;window.natively.trigger(id,15,callback,"nfc_write",params)};this.available=function(callback){let params={};window.natively.trigger(id,15,callback,"nfc_available",params)}}}class NativelyAppleSignInService{constructor(){const id=generateID();this.signin=function(callback){let params={};window.natively.trigger(id,16,callback,"apple_signin",params)}}}function generateID(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.natively={isDebug:false,min_app_version:0,app_version:0,injected:false,observers:[],isIOSApp:window.navigator.userAgent.includes("Natively/iOS"),isAndroidApp:window.navigator.userAgent.includes("Natively/Android"),setDebug:function(isDebug){window.natively.isDebug=isDebug},notify:function(min,current){window.natively.injected=true;if(min){window.natively.min_app_version=min}if(current){window.natively.app_version=current}const observers=window.natively.observers;if(natively.isDebug){console.log("[INFO] Notify observers: ",observers.length)}while(observers.length>0){const observer=observers.shift();observer()}},addObserver:function(fn){if(window.natively.injected){fn()}else{if(window.natively.isDebug){console.log(`[DEBUG] addObserver: ${fn}`)}window.natively.observers.push(fn)}},trigger:function(respId,minVersion,callback,method,body){const isTestVersion=window.natively.isDebug;if(!window.natively.injected){window.natively.addObserver((()=>{window.natively.trigger(respId,minVersion,callback,method,body)}));return}if(minVersion>window.natively.app_version){if(isTestVersion){alert(`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${minVersion}`)}return}if(callback){let fullMethodName;if(respId){fullMethodName=method+"_response"+"_"+respId}else{fullMethodName=method+"_response"}window[fullMethodName]=function(resp,err){$agent.response();if(err.message&&isTestVersion){alert(`[ERROR] Error message: ${err.message}`);return}if(isTestVersion){console.log(`[DEBUG] Callback method: ${fullMethodName}, body: ${JSON.stringify(resp)}, respId: ${respId}`)}callback(resp)};if(body){body.response_id=respId}else{body={response_id:respId}}}if(isTestVersion){console.log(`[DEBUG] Trigger method: ${method}, body: ${JSON.stringify(body)}`)}$agent.trigger(method,body)},openLogger:function(){$agent.natively_logger()},openConsole:function(){window.natively.trigger(undefined,30,undefined,"app_console")},closeApp:function(){window.natively.trigger(undefined,11,undefined,"app_close")},showProgress:function(toggle){window.natively.trigger(undefined,11,undefined,"app_show_progress",{toggle:toggle})},shareImage(image_url){window.natively.trigger(undefined,0,undefined,"share_image",{url:image_url})},shareText(text){window.natively.trigger(undefined,0,undefined,"share_text",{text:text})},shareTextAndImage(text,image_url){window.natively.trigger(undefined,0,undefined,"share_text_and_image",{url:image_url,text:text})},shareFile(file_url){window.natively.trigger(undefined,2,undefined,"share_file",{url:file_url})},openExternalURL(url,external){const params={};params.url=typeof url==="undefined"?"https://buildnatively.com":url;const isExternal=typeof external==="undefined"?false:external;params.view=isExternal?"external":"web";window.natively.trigger(undefined,18,undefined,"open_link",params)},openExternalAppIOS(url){window.natively.trigger(undefined,0,undefined,"open_app",{url:url})},openAppSettings(){window.natively.trigger(undefined,0,undefined,"open_appsettings")},hapticPatternIOS(pattern,delay){window.natively.trigger(undefined,7,undefined,"haptic_pattern",{pattern:pattern,delay:delay})},hapticImpactIOS(type){window.natively.trigger(undefined,7,undefined,"haptic_impact",{type:type})},hapticNotificationIOS(type){window.natively.trigger(undefined,7,undefined,"haptic_notification",{type:type})},showAppToast(type,text){const params={};params.text=typeof text==="undefined"?"":text;params.type=typeof type==="undefined"?"DEFAULT":type;window.natively.trigger(undefined,0,undefined,"show_toast",params)},showAppBanner(type,title,description){const params={};params.type=typeof type==="undefined"?"INFO":type;params.title=typeof title==="undefined"?"":title;params.description=typeof description==="undefined"?"":description;window.natively.trigger(undefined,0,undefined,"show_banner",params)},requestAppReview(){window.natively.trigger(undefined,0,undefined,"request_review")},setAppBackgroundColor(color){const params={color:color};window.natively.trigger(undefined,1,undefined,"app_background",params)},setAppProgressColor(color){const params={color:color};window.natively.trigger(undefined,1,undefined,"app_progress",params)},setAppSwipeNavigationIOS(toggle){const params={toggle:toggle};window.natively.trigger(undefined,1,undefined,"app_navigation",params)},setAppPullToRefresh(toggle){const params={toggle:toggle};window.natively.trigger(undefined,1,undefined,"app_pull",params)},setAppOrientation(orientation){const params={orientation:orientation};window.natively.trigger(undefined,3,undefined,"app_orientation",params)},setAppStatusBarStyleIOS(style){const params={style:style};window.natively.trigger(undefined,2,undefined,"status_bar_style",params)},hideLoadingScreen(){const show_loader=false;const auto_hide=true;const params={show_loader:show_loader,auto_hide:auto_hide};window.natively.trigger(undefined,17,undefined,"loading_screen",params)},showLoadingScreen(autoHide){const show_loader=true;const auto_hide=typeof autoHide==="undefined"?false:autoHide;const params={show_loader:show_loader,auto_hide:auto_hide};window.natively.trigger(undefined,17,undefined,"loading_screen",params)},async sendPushNotification(appId,payload,player_ids,isPreview){const filtered=player_ids.filter((id=>id.length>0));const include_player_ids=[...new Set(filtered)];let notification={app_id:isPreview?"be83022a-1d08-45d0-a07a-0c3655666e17":appId,include_player_ids:include_player_ids};if(payload.template_id){notification.template_id=payload.template_id}else{notification.headings={};notification.headings.en=payload.title||"Empty Title";notification.contents={};notification.contents.en=payload.message||"Empty Message";if(payload.subtitle){notification.subtitle={};notification.subtitle.en=payload.subtitle}if(payload.redirect_url){notification.url=payload.redirect_url}}const options={method:"POST",headers:{"Content-type":"application/json"},body:JSON.stringify(notification)};return await fetch("https://onesignal.com/api/v1/notifications",options)}};window.natively.addObserver((()=>window.natively.trigger(undefined,0,(resp=>{window.natively.min_app_version=resp.minSDKVersion;window.natively.app_version=resp.sdkVersion}),"app_info",{})));class NativelyInfo{constructor(){const id=generateID();this.browserInfo=function(){const isNativeApp=typeof $agent!=="undefined";const isIOSApp=window.navigator.userAgent.includes("Natively/iOS");const isAndroidApp=window.navigator.userAgent.includes("Natively/Android");return{isNativeApp:isNativeApp,isIOSApp:isIOSApp,isAndroidApp:isAndroidApp}};this.getAppInfo=function(app_info_callback){window.natively.trigger(id,0,app_info_callback,"app_info")};this.connectivity=function(connectivity_callback){window.natively.trigger(undefined,0,connectivity_callback,"connectivity")};this.app_state=function(app_state_callback){window.natively.trigger(undefined,19,app_state_callback,"app_state")}}}class NativelyClipboard{constructor(){const id=generateID();this.copy=function(text){window.natively.trigger(undefined,11,undefined,"clipboard_copy",{text:text})};this.paste=function(paste_callback){window.natively.trigger(id,11,paste_callback,"clipboard_paste")}}}class NativelyPagesCache{constructor(){const id=generateID();this.currentPageCached=function(current_page_cached_callback){window.natively.trigger(id,4,current_page_cached_callback,"current_page_cached")};this.storeCurrentPage=function(store_current_page_callback){window.natively.trigger(id,4,store_current_page_callback,"store_current_page")};this.resetCurrentPage=function(reset_current_page_callback){window.natively.trigger(id,4,reset_current_page_callback,"reset_current_page")};this.resetAll=function(reset_all_callback){window.natively.trigger(id,4,reset_all_callback,"reset_all")}}}class NativelyNotifications{constructor(){const id=generateID();this.getOneSignalId=function(onesignal_playerid_callback){window.natively.trigger(id,0,onesignal_playerid_callback,"onesignal_playerid")};this.requestPermission=function(fallbackToSettings,push_register_callback){window.natively.trigger(id,0,push_register_callback,"push_register",{fallbackToSettings:fallbackToSettings})};this.getPermissionStatus=function(push_permission_callback){window.natively.trigger(id,0,push_permission_callback,"push_permission")}}}class NativelyGeolocation{constructor(){const id=generateID();this.getUserGeolocation=function(distance,geolocation_callback){window.natively.trigger(id,0,geolocation_callback,"geolocation",{distance:distance})};this.requestPermission=function(geo_register_callback){window.natively.trigger(id,0,geo_register_callback,"geo_register")};this.getPermissionStatus=function(geo_permission_callback){window.natively.trigger(id,0,geo_permission_callback,"geo_permission")}}}class NativelyLocation{constructor(){const id=generateID();this.current=function(minAccuracyIOS,accuracyTypeIOS,priority_android,location_callback){window.natively.trigger(id,12,location_callback,"location_current",{minAccuracy:minAccuracyIOS,accuracyType:accuracyTypeIOS,priority:priority_android})};this.permission=function(location_permission_callback){window.natively.trigger(id,6,location_permission_callback,"location_permission")};this.start=function(interval,minAccuracyIOS,accuracyTypeIOS,priority_android,location_callback){window.natively.trigger(id,12,location_callback,"location_start",{minAccuracy:minAccuracyIOS,accuracyType:accuracyTypeIOS,priority:priority_android,interval:interval})};this.stop=function(){window.natively.trigger(id,3,undefined,"location_stop",{})};this.startBackground=function(interval,minAccuracyIOS,accuracyTypeIOS,priority_android,responseIdentifier,location_bg_callback){const params={};params.identifier=typeof responseIdentifier==="undefined"?"empty":responseIdentifier;params.interval=typeof interval==="undefined"?1e3*60:interval;params.minAccuracy=typeof minAccuracyIOS==="undefined"?50:minAccuracyIOS;params.accuracyType=typeof accuracyTypeIOS==="undefined"?"Best":accuracyTypeIOS;params.priority=typeof priority_android==="undefined"?"BALANCED":priority_android;window.natively.trigger(id,12,location_bg_callback,"location_start_bg",params)};this.statusBackground=function(location_bg_status_callback){window.natively.trigger(id,20,location_bg_status_callback,"location_status_bg",{})};this.stopBackground=function(location_bg_callback){window.natively.trigger(id,4,location_bg_callback,"location_stop_bg",{})}}}class NativelyMessage{constructor(){const id=generateID();this.sendSMS=function(body,recipient,send_sms_callback){const params={};params.body=typeof body==="undefined"?"":body;params.recipient=typeof recipient==="undefined"?"":recipient;window.natively.trigger(id,0,send_sms_callback,"send_sms",params)};this.sendEmail=function(subject,body,recipient,send_email_callback){const params={};params.subject=typeof subject==="undefined"?"":subject;params.body=typeof body==="undefined"?"":body;params.recipient=typeof recipient==="undefined"?"":recipient;window.natively.trigger(id,0,send_email_callback,"send_email",params)}}}class NativelyStorage{constructor(){const id=generateID();this.setStorageValue=function(key,value){window.natively.trigger(id,0,undefined,"set_storage_value",{key:key,value:value})};this.getStorageValue=function(key,get_storage_value_callback){window.natively.trigger(id,0,get_storage_value_callback,"get_storage_value",{key:key})};this.removeStorageValue=function(key){window.natively.trigger(id,0,undefined,"remove_storage_value",{key:key})};this.resetStorage=function(){window.natively.trigger(id,0,undefined,"reset_storage")}}}class NativelyBiometrics{constructor(allowPass){this.allowPass=allowPass;const id=generateID();this.checkBiometricsSupport=function(biometrics_support_callback){window.natively.trigger(id,0,biometrics_support_callback,"biometrics_support",{allowPass:allowPass})};this.checkCredentials=function(biometrics_has_credentials_callback){window.natively.trigger(id,0,biometrics_has_credentials_callback,"biometrics_has_credentials")};this.verifyUserIdentify=function(biometrics_verify_callback){window.natively.trigger(id,0,biometrics_verify_callback,"biometrics_verify",{allowPass:allowPass})};this.getUserCredentials=function(biometrics_auth_callback){window.natively.trigger(id,0,biometrics_auth_callback,"biometrics_auth",{allowPass:allowPass})};this.removeUserCredentials=function(biometrics_remove_credentials_callback){window.natively.trigger(id,0,biometrics_remove_credentials_callback,"biometrics_remove_credentials")};this.saveUserCredentials=function(login,password,biometrics_auth_callback){window.natively.trigger(id,0,biometrics_auth_callback,"biometrics_auth",{allowPass:allowPass,login:login,password:password})}}}class NativelyDatePicker{constructor(){const id=generateID();this.showDatePicker=function(title,description,type,style,datepicker_callback){let params={};params.type=typeof type==="undefined"?"DATE":type;params.style=typeof style==="undefined"?"LIGHT":style;params.title=typeof title==="undefined"?"":title;params.description=typeof description==="undefined"?"":description;window.natively.trigger(id,0,datepicker_callback,"datepicker",params)}}}class NativelyCamera{constructor(){const id=generateID();this.showCamera=function(type,quality,camera,open_camera_callback){let params={};params.type=typeof type==="undefined"?"photo":type;params.quality=typeof quality==="undefined"?"high":quality;params.camera=typeof camera==="undefined"?"BACK":camera;window.natively.trigger(id,2,open_camera_callback,"open_camera",params)}}}class NativelyHealth{constructor(){const id=generateID();this.available=function(available_callback){window.natively.trigger(id,10,available_callback,"health_available",{})};this.requestAuthorization=function(write_data_types,read_data_types,request_callback){window.natively.trigger(id,10,request_callback,"health_register",{write_data_types:write_data_types,read_data_types:read_data_types})};this.permissionStatus=function(data_type,callback){window.natively.trigger(id,10,callback,"health_permission",{data_type:data_type})};this.getAllCharacteristics=function(callback){window.natively.trigger(id,10,callback,"health_get_all_characteristics",{})};this.getStatisticQuantity=function(data_type,interval,start_date,end_date,callback){const obj={data_type:data_type,interval:interval};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,10,callback,"health_get_statistic_quantity",obj)};this.getDailySleepAnalysis=function(start_date,end_date,limit,callback){const obj={limit:limit||100};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,10,callback,"health_get_daily_sleep_analysis",obj)};this.getWorkouts=function(start_date,end_date,limit,callback){const obj={limit:limit||100};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,21,callback,"health_get_workouts",obj)};this.getActivitySummary=function(start_date,end_date,callback){const obj={};if(typeof start_date!=="undefined"){obj.start_date=start_date.getTime()}if(typeof end_date!=="undefined"){obj.end_date=end_date.getTime()}window.natively.trigger(id,10,callback,"health_get_activity_summary",obj)}}}class NativelyScanner{constructor(){const id=generateID();this.showScanner=function(open_scanner_callback){window.natively.trigger(id,2,open_scanner_callback,"open_scanner",{})}}}class NativelyPurchases{constructor(){const id=generateID();this.login=function(login,customerEmail,login_callback){const email=typeof customerEmail==="undefined"?"":customerEmail;window.natively.trigger(id,3,login_callback,"purchases_login",{login:login,email:email})};this.logout=function(logout_callback){window.natively.trigger(id,3,logout_callback,"purchases_logout",{})};this.customerId=function(customer_id_callback){window.natively.trigger(id,3,customer_id_callback,"purchases_customerid",{})};this.restore=function(restore_callback){window.natively.trigger(id,10,restore_callback,"purchases_restore",{})};this.purchasePackage=function(packageId,purchase_callback){window.natively.trigger(id,3,purchase_callback,"purchases_package",{packageId:packageId})};this.packagePrice=function(packageId,purchase_callback){window.natively.trigger(id,8,purchase_callback,"purchases_price",{packageId:packageId})}}}class NativelyContacts{constructor(){const id=generateID();this.getAllContacts=function(contacts_all_callback){window.natively.trigger(id,3,contacts_all_callback,"contacts_all",{})};this.createContact=function(firstName,lastName,email,phone,contacts_save_callback){let params={firstName:firstName};params.lastName=typeof lastName==="undefined"?"":lastName;params.email=typeof email==="undefined"?"":email;params.phone=typeof phone==="undefined"?"":phone;window.natively.trigger(id,3,contacts_save_callback,"contacts_save",params)}}}class NativelyMediaPicker{constructor(){const id=generateID();this.showMediaPicker=function(mediapicker_callback){window.natively.trigger(id,8,mediapicker_callback,"mediapicker",{})}}}class NativelyAudioRecorder{constructor(){const id=generateID();this.showRecorder=function(max_duration,record_callback){let params={};params.max_duration=typeof max_duration==="undefined"?0:max_duration;window.natively.trigger(id,13,record_callback,"record_start",params)}}}class NativelyAdmobBanner{constructor(config={iOSUnitId:"ca-app-pub-3940256099942544/2934735716",androidUnitId:"ca-app-pub-3940256099942544/6300978111",position:"BOTTOM",sizeType:"AUTO",custom_width:320,custom_height:50},setup_callback=undefined,preload_ad=false,preload_callback=undefined,show_ad=false,show_callback=undefined){const id=generateID();const params={};if(window.natively.isAndroidApp){params.unitId=typeof config.androidUnitId==="undefined"?"ca-app-pub-3940256099942544/6300978111":config.androidUnitId}else if(window.natively.isIOSApp){params.unitId=typeof config.iOSUnitId==="undefined"?"ca-app-pub-3940256099942544/2934735716":config.iOSUnitId}params.position=typeof config.position==="undefined"?"BOTTOM":config.position;params.sizeType=typeof config.sizeType==="undefined"?"AUTO":config.sizeType;params.width=typeof config.custom_width==="undefined"?320:config.width;params.height=typeof config.custom_height==="undefined"?50:config.height;window.natively.trigger(id,14,(function(resp){if(typeof setup_callback!=="undefined"){setup_callback(resp)}if(preload_ad){window.natively.trigger(id,14,(function(resp){if(typeof preload_callback!=="undefined"){preload_callback(resp)}if(show_ad){window.natively.trigger(id,14,show_callback,"bannerad_show",{})}}),"bannerad_load",{})}}),"bannerad_setup",params);this.loadAd=function(callback){window.natively.trigger(id,14,callback,"bannerad_load",{})};this.showBanner=function(callback){window.natively.trigger(id,14,callback,"bannerad_show",{})};this.hideBanner=function(callback){window.natively.trigger(id,14,callback,"bannerad_hide",{})};this.bannerIsReady=function(callback){window.natively.trigger(id,14,callback,"bannerad_ready",{})};this.bannerIsVisible=function(callback){window.natively.trigger(id,14,callback,"bannerad_visible",{})}}}class NativelyAdmobInterstitial{constructor(iOSUnitId="ca-app-pub-3940256099942544/4411468910",androidUnitId="ca-app-pub-3940256099942544/1033173712",setup_callback=undefined,auto_ad_reload=false,auto_ad_reload_callback=undefined){const id=generateID();let unitId;if(window.natively.isAndroidApp){unitId=typeof androidUnitId==="undefined"?"ca-app-pub-3940256099942544/1033173712":androidUnitId}else if(window.natively.isIOSApp){unitId=typeof iOSUnitId==="undefined"?"ca-app-pub-3940256099942544/4411468910":iOSUnitId}this.loadAd=function(callback){const params={};params.unitId=typeof unitId==="undefined"?"ca-app-pub-3940256099942544/4411468910":unitId;window.natively.trigger(id,14,callback,"interstitialad_setup",params)};this.showInterstitialAd=function(callback){window.natively.trigger(id,14,(function(resp){callback(resp);if(resp.event==="DID_DISMISS_AD"&&auto_ad_reload){const params={};params.unitId=unitId;setTimeout((()=>{window.natively.trigger(id,14,auto_ad_reload_callback,"interstitialad_setup",params)}),500)}}),"interstitialad_show",{})};this.interstitialIsReady=function(callback){window.natively.trigger(id,14,callback,"interstitialad_ready",{})};this.loadAd(setup_callback)}}class NativelyNFCService{constructor(readAlertMessage,writeAlertMessage,readDetectedMessage,writeDetectedMessage){const id=generateID();this.readAlertMessage=readAlertMessage;this.writeAlertMessage=writeAlertMessage;this.readDetectedMessage=readDetectedMessage;this.writeDetectedMessage=writeDetectedMessage;this.read=function(callback){let params={};params.alertMessage=typeof this.readAlertMessage==="undefined"?"please set readAlertMessage":this.readAlertMessage;params.detectedMessage=typeof this.readDetectedMessage==="undefined"?"readDetectedMessage":this.readDetectedMessage;window.natively.trigger(id,15,callback,"nfc_read",params)};this.write=function(recordId,recordData,callback){let params={};params.alertMessage=typeof this.writeAlertMessage==="undefined"?"please set writeAlertMessage":this.writeAlertMessage;params.detectedMessage=typeof this.writeDetectedMessage==="undefined"?"please set writeDetectedMessage":this.writeDetectedMessage;params.recordData=typeof recordData==="undefined"?"please set recordData":recordData;params.recordId=typeof recordId==="undefined"?"please set recordId":recordId;window.natively.trigger(id,15,callback,"nfc_write",params)};this.available=function(callback){let params={};window.natively.trigger(id,15,callback,"nfc_available",params)}}}class NativelyAppleSignInService{constructor(){const id=generateID();this.signin=function(callback){let params={};window.natively.trigger(id,16,callback,"apple_signin",params)}}}function generateID(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}export{NativelyAdmobBanner,NativelyAdmobInterstitial,NativelyAppleSignInService,NativelyAudioRecorder,NativelyBiometrics,NativelyCamera,NativelyClipboard,NativelyContacts,NativelyDatePicker,NativelyGeolocation,NativelyHealth,NativelyInfo,NativelyLocation,NativelyMediaPicker,NativelyMessage,NativelyNFCService,NativelyNotifications,NativelyPagesCache,NativelyPurchases,NativelyScanner,NativelyStorage};
|
|
@@ -0,0 +1,947 @@
|
|
|
1
|
+
window.natively = {
|
|
2
|
+
isDebug: false,
|
|
3
|
+
min_app_version: 0,
|
|
4
|
+
app_version: 0,
|
|
5
|
+
injected: false,
|
|
6
|
+
observers: [],
|
|
7
|
+
isIOSApp: window.navigator.userAgent.includes("Natively/iOS"),
|
|
8
|
+
isAndroidApp: window.navigator.userAgent.includes("Natively/Android"),
|
|
9
|
+
|
|
10
|
+
setDebug: function (isDebug) {
|
|
11
|
+
window.natively.isDebug = isDebug;
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
notify: function (min, current) {
|
|
15
|
+
window.natively.injected = true;
|
|
16
|
+
// Remove legacy min/current support later
|
|
17
|
+
if (min) {
|
|
18
|
+
window.natively.min_app_version = min;
|
|
19
|
+
}
|
|
20
|
+
if (current) {
|
|
21
|
+
window.natively.app_version = current;
|
|
22
|
+
}
|
|
23
|
+
const observers = window.natively.observers;
|
|
24
|
+
if (natively.isDebug) {
|
|
25
|
+
console.log("[INFO] Notify observers: ", observers.length);
|
|
26
|
+
}
|
|
27
|
+
while (observers.length > 0) {
|
|
28
|
+
const observer = observers.shift();
|
|
29
|
+
observer();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
addObserver: function (fn) {
|
|
34
|
+
if (window.natively.injected) {
|
|
35
|
+
fn();
|
|
36
|
+
} else {
|
|
37
|
+
if (window.natively.isDebug) {
|
|
38
|
+
console.log(`[DEBUG] addObserver: ${fn}`);
|
|
39
|
+
}
|
|
40
|
+
window.natively.observers.push(fn);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
trigger: function (respId, minVersion, callback, method, body) {
|
|
45
|
+
const isTestVersion = window.natively.isDebug;
|
|
46
|
+
if (!window.natively.injected) {
|
|
47
|
+
window.natively.addObserver(() => {
|
|
48
|
+
window.natively.trigger(respId, minVersion, callback, method, body);
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (minVersion > window.natively.app_version) {
|
|
53
|
+
if (isTestVersion) {
|
|
54
|
+
alert(
|
|
55
|
+
`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${minVersion}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (callback) {
|
|
61
|
+
let fullMethodName;
|
|
62
|
+
if (respId) {
|
|
63
|
+
fullMethodName = method + "_response" + "_" + respId;
|
|
64
|
+
} else {
|
|
65
|
+
fullMethodName = method + "_response";
|
|
66
|
+
}
|
|
67
|
+
window[fullMethodName] = function (resp, err) {
|
|
68
|
+
$agent.response();
|
|
69
|
+
if (err.message && isTestVersion) {
|
|
70
|
+
alert(`[ERROR] Error message: ${err.message}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (isTestVersion) {
|
|
74
|
+
console.log(
|
|
75
|
+
`[DEBUG] Callback method: ${fullMethodName}, body: ${JSON.stringify(
|
|
76
|
+
resp
|
|
77
|
+
)}, respId: ${respId}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
callback(resp);
|
|
81
|
+
};
|
|
82
|
+
if (body) {
|
|
83
|
+
body.response_id = respId;
|
|
84
|
+
} else {
|
|
85
|
+
body = { response_id: respId };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (isTestVersion) {
|
|
89
|
+
console.log(
|
|
90
|
+
`[DEBUG] Trigger method: ${method}, body: ${JSON.stringify(body)}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
$agent.trigger(method, body);
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
openLogger: function () {
|
|
97
|
+
$agent.natively_logger();
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// Not available right now
|
|
101
|
+
openConsole: function () {
|
|
102
|
+
window.natively.trigger(undefined, 30, undefined, "app_console");
|
|
103
|
+
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
closeApp: function () {
|
|
107
|
+
window.natively.trigger(undefined, 11, undefined, "app_close");
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
showProgress: function (toggle) {
|
|
111
|
+
window.natively.trigger(undefined, 11, undefined, "app_show_progress", { toggle });
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
shareImage(image_url) {
|
|
115
|
+
window.natively.trigger(undefined, 0, undefined, "share_image", {
|
|
116
|
+
url: image_url,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
shareText(text) {
|
|
121
|
+
window.natively.trigger(undefined, 0, undefined, "share_text", {
|
|
122
|
+
text,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
shareTextAndImage(text, image_url) {
|
|
127
|
+
window.natively.trigger(undefined, 0, undefined, "share_text_and_image", {
|
|
128
|
+
url: image_url,
|
|
129
|
+
text,
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
shareFile(file_url) {
|
|
134
|
+
window.natively.trigger(undefined, 2, undefined, "share_file", {
|
|
135
|
+
url: file_url,
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
openExternalURL(url, external) {
|
|
140
|
+
const params = {};
|
|
141
|
+
params.url = typeof url === "undefined" ? "https://buildnatively.com" : url;
|
|
142
|
+
const isExternal = typeof external === "undefined" ? false : external;
|
|
143
|
+
params.view = isExternal ? "external" : "web";
|
|
144
|
+
window.natively.trigger(undefined, 18, undefined, "open_link", params);
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
openExternalAppIOS(url) {
|
|
148
|
+
window.natively.trigger(undefined, 0, undefined, "open_app", {
|
|
149
|
+
url,
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
openAppSettings() {
|
|
154
|
+
window.natively.trigger(undefined, 0, undefined, "open_appsettings");
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
hapticPatternIOS(pattern, delay) {
|
|
158
|
+
window.natively.trigger(undefined, 7, undefined, "haptic_pattern", {
|
|
159
|
+
pattern,
|
|
160
|
+
delay
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
hapticImpactIOS(type) {
|
|
165
|
+
window.natively.trigger(undefined, 7, undefined, "haptic_impact", {
|
|
166
|
+
type,
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
hapticNotificationIOS(type) {
|
|
171
|
+
window.natively.trigger(undefined, 7, undefined, "haptic_notification", {
|
|
172
|
+
type,
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
showAppToast(type, text) {
|
|
177
|
+
const params = {};
|
|
178
|
+
params.text = typeof text === "undefined" ? "" : text;
|
|
179
|
+
params.type = typeof type === "undefined" ? "DEFAULT" : type;
|
|
180
|
+
window.natively.trigger(undefined, 0, undefined, "show_toast", params);
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
showAppBanner(type, title, description) {
|
|
184
|
+
const params = {};
|
|
185
|
+
params.type = typeof type === "undefined" ? "INFO" : type;
|
|
186
|
+
params.title = typeof title === "undefined" ? "" : title;
|
|
187
|
+
params.description = typeof description === "undefined" ? "" : description;
|
|
188
|
+
window.natively.trigger(undefined, 0, undefined, "show_banner", params);
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
requestAppReview() {
|
|
192
|
+
window.natively.trigger(undefined, 0, undefined, "request_review");
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
setAppBackgroundColor(color) {
|
|
196
|
+
const params = { color };
|
|
197
|
+
window.natively.trigger(undefined, 1, undefined, "app_background", params);
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
setAppProgressColor(color) {
|
|
201
|
+
const params = { color };
|
|
202
|
+
window.natively.trigger(undefined, 1, undefined, "app_progress", params);
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
setAppSwipeNavigationIOS(toggle) {
|
|
206
|
+
const params = { toggle };
|
|
207
|
+
window.natively.trigger(undefined, 1, undefined, "app_navigation", params);
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
setAppPullToRefresh(toggle) {
|
|
211
|
+
const params = { toggle };
|
|
212
|
+
window.natively.trigger(undefined, 1, undefined, "app_pull", params);
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
setAppOrientation(orientation) {
|
|
216
|
+
const params = { orientation };
|
|
217
|
+
window.natively.trigger(undefined, 3, undefined, "app_orientation", params);
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
setAppStatusBarStyleIOS(style) {
|
|
221
|
+
const params = { style };
|
|
222
|
+
window.natively.trigger(
|
|
223
|
+
undefined,
|
|
224
|
+
2,
|
|
225
|
+
undefined,
|
|
226
|
+
"status_bar_style",
|
|
227
|
+
params
|
|
228
|
+
);
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
hideLoadingScreen() {
|
|
232
|
+
const show_loader = false;
|
|
233
|
+
const auto_hide = true;
|
|
234
|
+
const params = { show_loader, auto_hide };
|
|
235
|
+
window.natively.trigger(
|
|
236
|
+
undefined,
|
|
237
|
+
17,
|
|
238
|
+
undefined,
|
|
239
|
+
"loading_screen",
|
|
240
|
+
params
|
|
241
|
+
);
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
showLoadingScreen(autoHide) {
|
|
245
|
+
const show_loader = true;
|
|
246
|
+
const auto_hide = typeof autoHide === "undefined" ? false : autoHide;
|
|
247
|
+
const params = { show_loader, auto_hide };
|
|
248
|
+
window.natively.trigger(
|
|
249
|
+
undefined,
|
|
250
|
+
17,
|
|
251
|
+
undefined,
|
|
252
|
+
"loading_screen",
|
|
253
|
+
params
|
|
254
|
+
);
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
async sendPushNotification(appId, payload, player_ids, isPreview) {
|
|
258
|
+
const filtered = player_ids.filter((id) => id.length > 0);
|
|
259
|
+
const include_player_ids = [...new Set(filtered)];
|
|
260
|
+
let notification = {
|
|
261
|
+
app_id: isPreview
|
|
262
|
+
? // Natively Preview App ID
|
|
263
|
+
"be83022a-1d08-45d0-a07a-0c3655666e17"
|
|
264
|
+
: appId,
|
|
265
|
+
include_player_ids,
|
|
266
|
+
};
|
|
267
|
+
if (payload.template_id) {
|
|
268
|
+
notification.template_id = payload.template_id;
|
|
269
|
+
} else {
|
|
270
|
+
notification.headings = {};
|
|
271
|
+
notification.headings.en = payload.title || "Empty Title";
|
|
272
|
+
notification.contents = {};
|
|
273
|
+
notification.contents.en = payload.message || "Empty Message";
|
|
274
|
+
if (payload.subtitle) {
|
|
275
|
+
notification.subtitle = {};
|
|
276
|
+
notification.subtitle.en = payload.subtitle;
|
|
277
|
+
}
|
|
278
|
+
if (payload.redirect_url) {
|
|
279
|
+
notification.url = payload.redirect_url;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const options = {
|
|
283
|
+
method: "POST",
|
|
284
|
+
headers: { "Content-type": "application/json" },
|
|
285
|
+
body: JSON.stringify(notification),
|
|
286
|
+
};
|
|
287
|
+
return await fetch("https://onesignal.com/api/v1/notifications", options);
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// Initial Setup
|
|
292
|
+
// Remove legacy min/current support later
|
|
293
|
+
window.natively.addObserver(() =>
|
|
294
|
+
window.natively.trigger(
|
|
295
|
+
undefined,
|
|
296
|
+
0,
|
|
297
|
+
(resp) => {
|
|
298
|
+
window.natively.min_app_version = resp.minSDKVersion;
|
|
299
|
+
window.natively.app_version = resp.sdkVersion;
|
|
300
|
+
},
|
|
301
|
+
"app_info",
|
|
302
|
+
{}
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
class NativelyInfo {
|
|
307
|
+
constructor() {
|
|
308
|
+
const id = generateID();
|
|
309
|
+
this.browserInfo = function () {
|
|
310
|
+
const isNativeApp = typeof $agent !== "undefined";
|
|
311
|
+
const isIOSApp = window.navigator.userAgent.includes("Natively/iOS");
|
|
312
|
+
const isAndroidApp = window.navigator.userAgent.includes("Natively/Android");
|
|
313
|
+
return { isNativeApp, isIOSApp, isAndroidApp };
|
|
314
|
+
};
|
|
315
|
+
this.getAppInfo = function (app_info_callback) {
|
|
316
|
+
window.natively.trigger(id, 0, app_info_callback, "app_info");
|
|
317
|
+
};
|
|
318
|
+
this.connectivity = function (connectivity_callback) {
|
|
319
|
+
window.natively.trigger(
|
|
320
|
+
undefined,
|
|
321
|
+
0,
|
|
322
|
+
connectivity_callback,
|
|
323
|
+
"connectivity"
|
|
324
|
+
);
|
|
325
|
+
};
|
|
326
|
+
// app_state_callback responsible for app state changes.
|
|
327
|
+
// e.g. app is in background or foreground (available >= 2.12.2)
|
|
328
|
+
this.app_state = function (app_state_callback) {
|
|
329
|
+
window.natively.trigger(undefined, 19, app_state_callback, "app_state");
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
class NativelyClipboard {
|
|
335
|
+
constructor() {
|
|
336
|
+
const id = generateID();
|
|
337
|
+
this.copy = function (text) {
|
|
338
|
+
window.natively.trigger(undefined, 11, undefined, "clipboard_copy", { text });
|
|
339
|
+
}
|
|
340
|
+
this.paste = function (paste_callback) {
|
|
341
|
+
window.natively.trigger(id, 11, paste_callback, "clipboard_paste");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// WebPage Caching Not Available
|
|
347
|
+
class NativelyPagesCache {
|
|
348
|
+
constructor() {
|
|
349
|
+
const id = generateID();
|
|
350
|
+
this.currentPageCached = function (current_page_cached_callback) {
|
|
351
|
+
window.natively.trigger(id, 4, current_page_cached_callback, "current_page_cached");
|
|
352
|
+
};
|
|
353
|
+
this.storeCurrentPage = function (store_current_page_callback) {
|
|
354
|
+
window.natively.trigger(id, 4, store_current_page_callback, "store_current_page");
|
|
355
|
+
};
|
|
356
|
+
this.resetCurrentPage = function (reset_current_page_callback) {
|
|
357
|
+
window.natively.trigger(id, 4, reset_current_page_callback, "reset_current_page");
|
|
358
|
+
};
|
|
359
|
+
this.resetAll = function (reset_all_callback) {
|
|
360
|
+
window.natively.trigger(id, 4, reset_all_callback, "reset_all");
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
class NativelyNotifications {
|
|
366
|
+
constructor() {
|
|
367
|
+
const id = generateID();
|
|
368
|
+
this.getOneSignalId = function (onesignal_playerid_callback) {
|
|
369
|
+
window.natively.trigger(
|
|
370
|
+
id,
|
|
371
|
+
0,
|
|
372
|
+
onesignal_playerid_callback,
|
|
373
|
+
"onesignal_playerid"
|
|
374
|
+
);
|
|
375
|
+
};
|
|
376
|
+
this.requestPermission = function (
|
|
377
|
+
fallbackToSettings,
|
|
378
|
+
push_register_callback
|
|
379
|
+
) {
|
|
380
|
+
window.natively.trigger(id, 0, push_register_callback, "push_register", {
|
|
381
|
+
fallbackToSettings,
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
this.getPermissionStatus = function (push_permission_callback) {
|
|
385
|
+
window.natively.trigger(
|
|
386
|
+
id,
|
|
387
|
+
0,
|
|
388
|
+
push_permission_callback,
|
|
389
|
+
"push_permission"
|
|
390
|
+
);
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Legacy use Natively Location
|
|
396
|
+
class NativelyGeolocation {
|
|
397
|
+
constructor() {
|
|
398
|
+
const id = generateID();
|
|
399
|
+
this.getUserGeolocation = function (distance, geolocation_callback) {
|
|
400
|
+
window.natively.trigger(id, 0, geolocation_callback, "geolocation", {
|
|
401
|
+
distance,
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
this.requestPermission = function (geo_register_callback) {
|
|
405
|
+
window.natively.trigger(id, 0, geo_register_callback, "geo_register");
|
|
406
|
+
};
|
|
407
|
+
this.getPermissionStatus = function (geo_permission_callback) {
|
|
408
|
+
window.natively.trigger(id, 0, geo_permission_callback, "geo_permission");
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
class NativelyLocation {
|
|
414
|
+
constructor() {
|
|
415
|
+
const id = generateID();
|
|
416
|
+
// minAccuracyIOS = 0 - 5000 m
|
|
417
|
+
// accuracyTypeIOS = BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers
|
|
418
|
+
// priority_android = HIGH or BALANCED
|
|
419
|
+
this.current = function (minAccuracyIOS, accuracyTypeIOS, priority_android, location_callback) {
|
|
420
|
+
window.natively.trigger(id, 12, location_callback, "location_current", {
|
|
421
|
+
minAccuracy: minAccuracyIOS,
|
|
422
|
+
accuracyType: accuracyTypeIOS,
|
|
423
|
+
priority: priority_android
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
// "AWLAYS" - background
|
|
427
|
+
// "IN_USE" - foreground
|
|
428
|
+
// "DENIED" - not determined or denied
|
|
429
|
+
this.permission = function (location_permission_callback) {
|
|
430
|
+
window.natively.trigger(id, 6, location_permission_callback, "location_permission");
|
|
431
|
+
};
|
|
432
|
+
this.start = function (interval, minAccuracyIOS, accuracyTypeIOS, priority_android, location_callback) {
|
|
433
|
+
window.natively.trigger(id, 12, location_callback, "location_start", {
|
|
434
|
+
minAccuracy: minAccuracyIOS,
|
|
435
|
+
accuracyType: accuracyTypeIOS,
|
|
436
|
+
priority: priority_android,
|
|
437
|
+
interval
|
|
438
|
+
});
|
|
439
|
+
};
|
|
440
|
+
this.stop = function () {
|
|
441
|
+
window.natively.trigger(id, 3, undefined, "location_stop", {});
|
|
442
|
+
};
|
|
443
|
+
// minAccuracyIOS = 0 - 5000 m
|
|
444
|
+
// accuracyTypeIOS = BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers
|
|
445
|
+
// priority_android = HIGH or BALANCED
|
|
446
|
+
// interval = in seconds e.g. 60 = 1 minute
|
|
447
|
+
this.startBackground = function (interval, minAccuracyIOS, accuracyTypeIOS, priority_android, responseIdentifier, location_bg_callback) {
|
|
448
|
+
const params = {};
|
|
449
|
+
params.identifier = typeof responseIdentifier === "undefined" ? "empty" : responseIdentifier;
|
|
450
|
+
params.interval = typeof interval === "undefined" ? 1000 * 60 : interval;
|
|
451
|
+
params.minAccuracy = typeof minAccuracyIOS === "undefined" ? 50 : minAccuracyIOS;
|
|
452
|
+
params.accuracyType = typeof accuracyTypeIOS === "undefined" ? "Best" : accuracyTypeIOS;
|
|
453
|
+
params.priority = typeof priority_android === "undefined" ? "BALANCED" : priority_android;
|
|
454
|
+
window.natively.trigger(id, 12, location_bg_callback, "location_start_bg", params);
|
|
455
|
+
};
|
|
456
|
+
this.statusBackground = function (location_bg_status_callback) {
|
|
457
|
+
window.natively.trigger(id, 20, location_bg_status_callback, "location_status_bg", {});
|
|
458
|
+
}
|
|
459
|
+
this.stopBackground = function (location_bg_callback) {
|
|
460
|
+
window.natively.trigger(id, 4, location_bg_callback, "location_stop_bg", {});
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
class NativelyMessage {
|
|
466
|
+
constructor() {
|
|
467
|
+
const id = generateID();
|
|
468
|
+
this.sendSMS = function (body, recipient, send_sms_callback) {
|
|
469
|
+
const params = {};
|
|
470
|
+
params.body = typeof body === "undefined" ? "" : body;
|
|
471
|
+
params.recipient = typeof recipient === "undefined" ? "" : recipient;
|
|
472
|
+
window.natively.trigger(id, 0, send_sms_callback, "send_sms", params);
|
|
473
|
+
};
|
|
474
|
+
this.sendEmail = function (subject, body, recipient, send_email_callback) {
|
|
475
|
+
const params = {};
|
|
476
|
+
params.subject = typeof subject === "undefined" ? "" : subject;
|
|
477
|
+
params.body = typeof body === "undefined" ? "" : body;
|
|
478
|
+
params.recipient = typeof recipient === "undefined" ? "" : recipient;
|
|
479
|
+
window.natively.trigger(id, 0, send_email_callback, "send_email", params);
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
class NativelyStorage {
|
|
485
|
+
constructor() {
|
|
486
|
+
const id = generateID();
|
|
487
|
+
this.setStorageValue = function (key, value) {
|
|
488
|
+
window.natively.trigger(id, 0, undefined, "set_storage_value", {
|
|
489
|
+
key,
|
|
490
|
+
value,
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
this.getStorageValue = function (key, get_storage_value_callback) {
|
|
494
|
+
window.natively.trigger(
|
|
495
|
+
id,
|
|
496
|
+
0,
|
|
497
|
+
get_storage_value_callback,
|
|
498
|
+
"get_storage_value",
|
|
499
|
+
{ key }
|
|
500
|
+
);
|
|
501
|
+
};
|
|
502
|
+
this.removeStorageValue = function (key) {
|
|
503
|
+
window.natively.trigger(id, 0, undefined, "remove_storage_value", {
|
|
504
|
+
key,
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
this.resetStorage = function () {
|
|
508
|
+
window.natively.trigger(id, 0, undefined, "reset_storage");
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
class NativelyBiometrics {
|
|
514
|
+
constructor(allowPass) {
|
|
515
|
+
this.allowPass = allowPass;
|
|
516
|
+
const id = generateID();
|
|
517
|
+
this.checkBiometricsSupport = function (biometrics_support_callback) {
|
|
518
|
+
window.natively.trigger(
|
|
519
|
+
id,
|
|
520
|
+
0,
|
|
521
|
+
biometrics_support_callback,
|
|
522
|
+
"biometrics_support",
|
|
523
|
+
{ allowPass }
|
|
524
|
+
);
|
|
525
|
+
};
|
|
526
|
+
this.checkCredentials = function (biometrics_has_credentials_callback) {
|
|
527
|
+
window.natively.trigger(
|
|
528
|
+
id,
|
|
529
|
+
0,
|
|
530
|
+
biometrics_has_credentials_callback,
|
|
531
|
+
"biometrics_has_credentials"
|
|
532
|
+
);
|
|
533
|
+
};
|
|
534
|
+
this.verifyUserIdentify = function (biometrics_verify_callback) {
|
|
535
|
+
window.natively.trigger(
|
|
536
|
+
id,
|
|
537
|
+
0,
|
|
538
|
+
biometrics_verify_callback,
|
|
539
|
+
"biometrics_verify",
|
|
540
|
+
{ allowPass }
|
|
541
|
+
);
|
|
542
|
+
};
|
|
543
|
+
this.getUserCredentials = function (biometrics_auth_callback) {
|
|
544
|
+
window.natively.trigger(
|
|
545
|
+
id,
|
|
546
|
+
0,
|
|
547
|
+
biometrics_auth_callback,
|
|
548
|
+
"biometrics_auth",
|
|
549
|
+
{ allowPass }
|
|
550
|
+
);
|
|
551
|
+
};
|
|
552
|
+
this.removeUserCredentials = function (
|
|
553
|
+
biometrics_remove_credentials_callback
|
|
554
|
+
) {
|
|
555
|
+
window.natively.trigger(
|
|
556
|
+
id,
|
|
557
|
+
0,
|
|
558
|
+
biometrics_remove_credentials_callback,
|
|
559
|
+
"biometrics_remove_credentials"
|
|
560
|
+
);
|
|
561
|
+
};
|
|
562
|
+
this.saveUserCredentials = function (
|
|
563
|
+
login,
|
|
564
|
+
password,
|
|
565
|
+
biometrics_auth_callback
|
|
566
|
+
) {
|
|
567
|
+
window.natively.trigger(
|
|
568
|
+
id,
|
|
569
|
+
0,
|
|
570
|
+
biometrics_auth_callback,
|
|
571
|
+
"biometrics_auth",
|
|
572
|
+
{
|
|
573
|
+
allowPass,
|
|
574
|
+
login,
|
|
575
|
+
password,
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
class NativelyDatePicker {
|
|
583
|
+
constructor() {
|
|
584
|
+
const id = generateID();
|
|
585
|
+
this.showDatePicker = function (
|
|
586
|
+
title,
|
|
587
|
+
description,
|
|
588
|
+
type,
|
|
589
|
+
style,
|
|
590
|
+
datepicker_callback
|
|
591
|
+
) {
|
|
592
|
+
let params = {};
|
|
593
|
+
params.type = typeof type === "undefined" ? "DATE" : type;
|
|
594
|
+
params.style = typeof style === "undefined" ? "LIGHT" : style;
|
|
595
|
+
params.title = typeof title === "undefined" ? "" : title;
|
|
596
|
+
params.description = typeof description === "undefined" ? "" : description;
|
|
597
|
+
window.natively.trigger(id, 0, datepicker_callback, "datepicker", params);
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
class NativelyCamera {
|
|
603
|
+
constructor() {
|
|
604
|
+
const id = generateID();
|
|
605
|
+
this.showCamera = function (type, quality, camera, open_camera_callback) {
|
|
606
|
+
let params = {};
|
|
607
|
+
params.type = typeof type === "undefined" ? "photo" : type;
|
|
608
|
+
params.quality = typeof quality === "undefined" ? "high" : quality;
|
|
609
|
+
params.camera = typeof camera === "undefined" ? "BACK" : camera;
|
|
610
|
+
window.natively.trigger(
|
|
611
|
+
id,
|
|
612
|
+
2,
|
|
613
|
+
open_camera_callback,
|
|
614
|
+
"open_camera",
|
|
615
|
+
params
|
|
616
|
+
);
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
class NativelyHealth {
|
|
622
|
+
constructor() {
|
|
623
|
+
const id = generateID();
|
|
624
|
+
this.available = function (available_callback) {
|
|
625
|
+
window.natively.trigger(id, 10, available_callback, "health_available", {});
|
|
626
|
+
};
|
|
627
|
+
this.requestAuthorization = function (write_data_types, read_data_types, request_callback) {
|
|
628
|
+
window.natively.trigger(id, 10, request_callback, "health_register", {
|
|
629
|
+
write_data_types,
|
|
630
|
+
read_data_types
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
// Write only
|
|
634
|
+
this.permissionStatus = function (data_type, callback) {
|
|
635
|
+
window.natively.trigger(id, 10, callback, "health_permission", {
|
|
636
|
+
data_type
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
this.getAllCharacteristics = function (callback) {
|
|
640
|
+
window.natively.trigger(id, 10, callback, "health_get_all_characteristics", {});
|
|
641
|
+
}
|
|
642
|
+
this.getStatisticQuantity = function (data_type, interval, start_date, end_date, callback) {
|
|
643
|
+
const obj = {
|
|
644
|
+
data_type,
|
|
645
|
+
interval
|
|
646
|
+
};
|
|
647
|
+
if (typeof start_date !== "undefined") {
|
|
648
|
+
obj.start_date = start_date.getTime();
|
|
649
|
+
}
|
|
650
|
+
if (typeof end_date !== "undefined") {
|
|
651
|
+
obj.end_date = end_date.getTime();
|
|
652
|
+
}
|
|
653
|
+
window.natively.trigger(id, 10, callback, "health_get_statistic_quantity", obj);
|
|
654
|
+
}
|
|
655
|
+
this.getDailySleepAnalysis = function (start_date, end_date, limit, callback) {
|
|
656
|
+
const obj = { limit: limit || 100 };
|
|
657
|
+
if (typeof start_date !== "undefined") {
|
|
658
|
+
obj.start_date = start_date.getTime();
|
|
659
|
+
}
|
|
660
|
+
if (typeof end_date !== "undefined") {
|
|
661
|
+
obj.end_date = end_date.getTime();
|
|
662
|
+
}
|
|
663
|
+
window.natively.trigger(id, 10, callback, "health_get_daily_sleep_analysis", obj);
|
|
664
|
+
}
|
|
665
|
+
this.getWorkouts = function (start_date, end_date, limit, callback) {
|
|
666
|
+
const obj = { limit: limit || 100 };
|
|
667
|
+
if (typeof start_date !== "undefined") {
|
|
668
|
+
obj.start_date = start_date.getTime();
|
|
669
|
+
}
|
|
670
|
+
if (typeof end_date !== "undefined") {
|
|
671
|
+
obj.end_date = end_date.getTime();
|
|
672
|
+
}
|
|
673
|
+
window.natively.trigger(id, 21, callback, "health_get_workouts", obj);
|
|
674
|
+
}
|
|
675
|
+
this.getActivitySummary = function (start_date, end_date, callback) {
|
|
676
|
+
const obj = {};
|
|
677
|
+
if (typeof start_date !== "undefined") {
|
|
678
|
+
obj.start_date = start_date.getTime();
|
|
679
|
+
}
|
|
680
|
+
if (typeof end_date !== "undefined") {
|
|
681
|
+
obj.end_date = end_date.getTime();
|
|
682
|
+
}
|
|
683
|
+
window.natively.trigger(id, 10, callback, "health_get_activity_summary", obj);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
class NativelyScanner {
|
|
689
|
+
constructor() {
|
|
690
|
+
const id = generateID();
|
|
691
|
+
this.showScanner = function (open_scanner_callback) {
|
|
692
|
+
window.natively.trigger(id, 2, open_scanner_callback, "open_scanner", {});
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
class NativelyPurchases {
|
|
698
|
+
constructor() {
|
|
699
|
+
const id = generateID();
|
|
700
|
+
this.login = function (login, customerEmail, login_callback) {
|
|
701
|
+
const email = typeof customerEmail === "undefined" ? "" : customerEmail;
|
|
702
|
+
window.natively.trigger(id, 3, login_callback, "purchases_login", {
|
|
703
|
+
login,
|
|
704
|
+
email
|
|
705
|
+
});
|
|
706
|
+
};
|
|
707
|
+
this.logout = function (logout_callback) {
|
|
708
|
+
window.natively.trigger(id, 3, logout_callback, "purchases_logout", {});
|
|
709
|
+
};
|
|
710
|
+
this.customerId = function (customer_id_callback) {
|
|
711
|
+
window.natively.trigger(
|
|
712
|
+
id,
|
|
713
|
+
3,
|
|
714
|
+
customer_id_callback,
|
|
715
|
+
"purchases_customerid",
|
|
716
|
+
{}
|
|
717
|
+
);
|
|
718
|
+
};
|
|
719
|
+
this.restore = function (restore_callback) {
|
|
720
|
+
window.natively.trigger(id, 10, restore_callback, "purchases_restore", {});
|
|
721
|
+
};
|
|
722
|
+
this.purchasePackage = function (packageId, purchase_callback) {
|
|
723
|
+
window.natively.trigger(id, 3, purchase_callback, "purchases_package", {
|
|
724
|
+
packageId,
|
|
725
|
+
});
|
|
726
|
+
};
|
|
727
|
+
this.packagePrice = function (packageId, purchase_callback) {
|
|
728
|
+
window.natively.trigger(id, 8, purchase_callback, "purchases_price", {
|
|
729
|
+
packageId,
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
class NativelyContacts {
|
|
736
|
+
constructor() {
|
|
737
|
+
const id = generateID();
|
|
738
|
+
this.getAllContacts = function (contacts_all_callback) {
|
|
739
|
+
window.natively.trigger(id, 3, contacts_all_callback, "contacts_all", {});
|
|
740
|
+
};
|
|
741
|
+
this.createContact = function (
|
|
742
|
+
firstName,
|
|
743
|
+
lastName,
|
|
744
|
+
email,
|
|
745
|
+
phone,
|
|
746
|
+
contacts_save_callback
|
|
747
|
+
) {
|
|
748
|
+
let params = { firstName };
|
|
749
|
+
params.lastName = typeof lastName === "undefined" ? "" : lastName;
|
|
750
|
+
params.email = typeof email === "undefined" ? "" : email;
|
|
751
|
+
params.phone = typeof phone === "undefined" ? "" : phone;
|
|
752
|
+
window.natively.trigger(
|
|
753
|
+
id,
|
|
754
|
+
3,
|
|
755
|
+
contacts_save_callback,
|
|
756
|
+
"contacts_save",
|
|
757
|
+
params
|
|
758
|
+
);
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
class NativelyMediaPicker {
|
|
764
|
+
constructor() {
|
|
765
|
+
const id = generateID();
|
|
766
|
+
this.showMediaPicker = function (
|
|
767
|
+
mediapicker_callback
|
|
768
|
+
) {
|
|
769
|
+
window.natively.trigger(id, 8, mediapicker_callback, "mediapicker", {});
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
class NativelyAudioRecorder {
|
|
775
|
+
constructor() {
|
|
776
|
+
const id = generateID();
|
|
777
|
+
this.showRecorder = function (
|
|
778
|
+
max_duration,
|
|
779
|
+
record_callback
|
|
780
|
+
) {
|
|
781
|
+
let params = {}
|
|
782
|
+
params.max_duration = typeof max_duration === "undefined" ? 0 : max_duration;
|
|
783
|
+
window.natively.trigger(id, 13, record_callback, "record_start", params);
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// >=2.9.0
|
|
789
|
+
// Can be only one instance of NativelyAdmobBanner per page
|
|
790
|
+
// Make sure to use this an not reload page a lot
|
|
791
|
+
class NativelyAdmobBanner {
|
|
792
|
+
constructor(
|
|
793
|
+
config = {
|
|
794
|
+
iOSUnitId: "ca-app-pub-3940256099942544/2934735716",
|
|
795
|
+
androidUnitId: "ca-app-pub-3940256099942544/6300978111",
|
|
796
|
+
position: "BOTTOM",
|
|
797
|
+
sizeType: "AUTO",
|
|
798
|
+
custom_width: 320,
|
|
799
|
+
custom_height: 50
|
|
800
|
+
},
|
|
801
|
+
setup_callback = undefined, // function(resp) { console.log(resp) }
|
|
802
|
+
preload_ad = false, // Load ad on init
|
|
803
|
+
preload_callback = undefined, // function(resp) { console.log(resp) }
|
|
804
|
+
show_ad = false, // Show ad on init
|
|
805
|
+
show_callback = undefined, // function(resp) { console.log(resp) }
|
|
806
|
+
) {
|
|
807
|
+
const id = generateID();
|
|
808
|
+
const params = {};
|
|
809
|
+
if (window.natively.isAndroidApp) {
|
|
810
|
+
params.unitId = (typeof config.androidUnitId === "undefined") ? "ca-app-pub-3940256099942544/6300978111" : config.androidUnitId;
|
|
811
|
+
} else if (window.natively.isIOSApp) {
|
|
812
|
+
params.unitId = (typeof config.iOSUnitId === "undefined") ? "ca-app-pub-3940256099942544/2934735716" : config.iOSUnitId;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
params.position = (typeof config.position === "undefined") ? "BOTTOM" : config.position;
|
|
816
|
+
params.sizeType = (typeof config.sizeType === "undefined") ? "AUTO" : config.sizeType;
|
|
817
|
+
params.width = (typeof config.custom_width === "undefined") ? 320 : config.width;
|
|
818
|
+
params.height = (typeof config.custom_height === "undefined") ? 50 : config.height;
|
|
819
|
+
window.natively.trigger(id, 14, function (resp) {
|
|
820
|
+
if (typeof setup_callback !== "undefined") {
|
|
821
|
+
setup_callback(resp);
|
|
822
|
+
}
|
|
823
|
+
if (preload_ad) {
|
|
824
|
+
window.natively.trigger(id, 14, function (resp) {
|
|
825
|
+
if (typeof preload_callback !== "undefined") {
|
|
826
|
+
preload_callback(resp);
|
|
827
|
+
}
|
|
828
|
+
if (show_ad) {
|
|
829
|
+
window.natively.trigger(id, 14, show_callback, "bannerad_show", {});
|
|
830
|
+
}
|
|
831
|
+
}, "bannerad_load", {});
|
|
832
|
+
}
|
|
833
|
+
}, "bannerad_setup", params);
|
|
834
|
+
|
|
835
|
+
this.loadAd = function (callback) {
|
|
836
|
+
window.natively.trigger(id, 14, callback, "bannerad_load", {});
|
|
837
|
+
};
|
|
838
|
+
this.showBanner = function (callback) {
|
|
839
|
+
window.natively.trigger(id, 14, callback, "bannerad_show", {});
|
|
840
|
+
};
|
|
841
|
+
this.hideBanner = function (callback) {
|
|
842
|
+
window.natively.trigger(id, 14, callback, "bannerad_hide", {});
|
|
843
|
+
};
|
|
844
|
+
this.bannerIsReady = function (callback) {
|
|
845
|
+
window.natively.trigger(id, 14, callback, "bannerad_ready", {});
|
|
846
|
+
};
|
|
847
|
+
this.bannerIsVisible = function (callback) {
|
|
848
|
+
window.natively.trigger(id, 14, callback, "bannerad_visible", {});
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// >=2.9.0
|
|
854
|
+
// Can be only one instance of NativelyAdmobInterstitial per page
|
|
855
|
+
// Make sure to use this an not reload page a lot
|
|
856
|
+
class NativelyAdmobInterstitial {
|
|
857
|
+
constructor(
|
|
858
|
+
iOSUnitId = "ca-app-pub-3940256099942544/4411468910",
|
|
859
|
+
androidUnitId = "ca-app-pub-3940256099942544/1033173712",
|
|
860
|
+
setup_callback = undefined, // function(resp) { console.log(resp) }
|
|
861
|
+
auto_ad_reload = false, // Reload ad after showing
|
|
862
|
+
auto_ad_reload_callback = undefined, // function(resp) { console.log(resp) }
|
|
863
|
+
) {
|
|
864
|
+
const id = generateID();
|
|
865
|
+
let unitId;
|
|
866
|
+
if (window.natively.isAndroidApp) {
|
|
867
|
+
unitId = (typeof androidUnitId === "undefined") ? "ca-app-pub-3940256099942544/1033173712" : androidUnitId;
|
|
868
|
+
} else if (window.natively.isIOSApp) {
|
|
869
|
+
unitId = (typeof iOSUnitId === "undefined") ? "ca-app-pub-3940256099942544/4411468910" : iOSUnitId;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
this.loadAd = function (callback) {
|
|
873
|
+
const params = {};
|
|
874
|
+
params.unitId = (typeof unitId === "undefined") ? "ca-app-pub-3940256099942544/4411468910" : unitId;
|
|
875
|
+
window.natively.trigger(id, 14, callback, "interstitialad_setup", params);
|
|
876
|
+
};
|
|
877
|
+
this.showInterstitialAd = function (callback) {
|
|
878
|
+
window.natively.trigger(id, 14, function (resp) {
|
|
879
|
+
callback(resp);
|
|
880
|
+
if (resp.event === "DID_DISMISS_AD" && auto_ad_reload) {
|
|
881
|
+
const params = {};
|
|
882
|
+
params.unitId = unitId;
|
|
883
|
+
setTimeout(() => {
|
|
884
|
+
window.natively.trigger(id, 14, auto_ad_reload_callback, "interstitialad_setup", params);
|
|
885
|
+
}, 500);
|
|
886
|
+
}
|
|
887
|
+
}, "interstitialad_show", {});
|
|
888
|
+
};
|
|
889
|
+
this.interstitialIsReady = function (callback) {
|
|
890
|
+
window.natively.trigger(id, 14, callback, "interstitialad_ready", {});
|
|
891
|
+
};
|
|
892
|
+
this.loadAd(setup_callback);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// >=2.10.0
|
|
897
|
+
class NativelyNFCService {
|
|
898
|
+
constructor(
|
|
899
|
+
readAlertMessage,
|
|
900
|
+
writeAlertMessage,
|
|
901
|
+
readDetectedMessage,
|
|
902
|
+
writeDetectedMessage
|
|
903
|
+
) {
|
|
904
|
+
const id = generateID();
|
|
905
|
+
this.readAlertMessage = readAlertMessage;
|
|
906
|
+
this.writeAlertMessage = writeAlertMessage;
|
|
907
|
+
this.readDetectedMessage = readDetectedMessage;
|
|
908
|
+
this.writeDetectedMessage = writeDetectedMessage;
|
|
909
|
+
this.read = function (callback) {
|
|
910
|
+
let params = {}
|
|
911
|
+
params.alertMessage = typeof this.readAlertMessage === "undefined" ? "please set readAlertMessage" : this.readAlertMessage;
|
|
912
|
+
params.detectedMessage = typeof this.readDetectedMessage === "undefined" ? "readDetectedMessage" : this.readDetectedMessage;
|
|
913
|
+
window.natively.trigger(id, 15, callback, "nfc_read", params);
|
|
914
|
+
};
|
|
915
|
+
this.write = function (recordId, recordData, callback) {
|
|
916
|
+
let params = {}
|
|
917
|
+
params.alertMessage = typeof this.writeAlertMessage === "undefined" ? "please set writeAlertMessage" : this.writeAlertMessage;
|
|
918
|
+
params.detectedMessage = typeof this.writeDetectedMessage === "undefined" ? "please set writeDetectedMessage" : this.writeDetectedMessage;
|
|
919
|
+
params.recordData = typeof recordData === "undefined" ? "please set recordData" : recordData;
|
|
920
|
+
params.recordId = typeof recordId === "undefined" ? "please set recordId" : recordId;
|
|
921
|
+
window.natively.trigger(id, 15, callback, "nfc_write", params);
|
|
922
|
+
};
|
|
923
|
+
this.available = function (callback) {
|
|
924
|
+
let params = {}
|
|
925
|
+
window.natively.trigger(id, 15, callback, "nfc_available", params);
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// >=2.11.0
|
|
931
|
+
class NativelyAppleSignInService {
|
|
932
|
+
constructor() {
|
|
933
|
+
const id = generateID();
|
|
934
|
+
this.signin = function (callback) {
|
|
935
|
+
let params = {}
|
|
936
|
+
window.natively.trigger(id, 16, callback, "apple_signin", params);
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
function generateID() {
|
|
944
|
+
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
export { NativelyAdmobBanner, NativelyAdmobInterstitial, NativelyAppleSignInService, NativelyAudioRecorder, NativelyBiometrics, NativelyCamera, NativelyClipboard, NativelyContacts, NativelyDatePicker, NativelyGeolocation, NativelyHealth, NativelyInfo, NativelyLocation, NativelyMediaPicker, NativelyMessage, NativelyNFCService, NativelyNotifications, NativelyPagesCache, NativelyPurchases, NativelyScanner, NativelyStorage };
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "natively",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.2",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "natively-frontend.min.
|
|
5
|
+
"main": "natively-frontend.min.mjs",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
8
|
+
"build": "rollup -c && terser natively-frontend.mjs -o natively-frontend.min.mjs",
|
|
7
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
10
|
},
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/buildnatively/js-sdk.git"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
16
|
"natively"
|
|
@@ -16,7 +18,7 @@
|
|
|
16
18
|
"author": "Roman Furman",
|
|
17
19
|
"license": "ISC",
|
|
18
20
|
"bugs": {
|
|
19
|
-
"url": "https://github.com/
|
|
21
|
+
"url": "https://github.com/buildnatively/js-sdk/issues"
|
|
20
22
|
},
|
|
21
|
-
"homepage": "https://github.com/
|
|
23
|
+
"homepage": "https://github.com/buildnatively/js-sdk#readme"
|
|
22
24
|
}
|