natively 2.0.1 → 2.2.0
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/natively-frontend.js +27 -5
- package/natively-frontend.min.js +1 -1
- package/package.json +1 -1
package/natively-frontend.js
CHANGED
|
@@ -239,6 +239,12 @@ window.natively.addObserver(() =>
|
|
|
239
239
|
class NativelyInfo {
|
|
240
240
|
constructor() {
|
|
241
241
|
const id = generateID();
|
|
242
|
+
this.browserInfo = function () {
|
|
243
|
+
const isNativeApp = typeof $agent !== undefined;
|
|
244
|
+
const isIOSApp = window.navigator.userAgent.includes("Natively/iOS");
|
|
245
|
+
const isAndroidApp = window.navigator.userAgent.includes("Natively/Android");
|
|
246
|
+
return { isNativeApp, isIOSApp, isAndroidApp };
|
|
247
|
+
};
|
|
242
248
|
this.getAppInfo = function (app_info_callback) {
|
|
243
249
|
window.natively.trigger(id, 0, app_info_callback, "app_info");
|
|
244
250
|
};
|
|
@@ -253,7 +259,7 @@ class NativelyInfo {
|
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
261
|
|
|
256
|
-
// WebPage Caching
|
|
262
|
+
// WebPage Caching Not Available
|
|
257
263
|
class NativelyPagesCache {
|
|
258
264
|
constructor() {
|
|
259
265
|
const id = generateID();
|
|
@@ -323,19 +329,35 @@ class NativelyGeolocation {
|
|
|
323
329
|
class NativelyLocation {
|
|
324
330
|
constructor() {
|
|
325
331
|
const id = generateID();
|
|
326
|
-
|
|
332
|
+
// priority_android = HIGH or BALANCED
|
|
333
|
+
// accuracy_ios = 0 - 5000 m
|
|
334
|
+
this.current = function (accuracy_ios, priority_android, location_callback) {
|
|
327
335
|
window.natively.trigger(id, 3, location_callback, "location_current", {
|
|
328
|
-
accuracy,
|
|
336
|
+
accuracy: accuracy_ios,
|
|
337
|
+
priority: priority_android
|
|
329
338
|
});
|
|
330
339
|
};
|
|
331
|
-
this.start = function (
|
|
340
|
+
this.start = function (interval, accuracy_ios, priority_android, location_callback) {
|
|
332
341
|
window.natively.trigger(id, 3, location_callback, "location_start", {
|
|
333
|
-
accuracy,
|
|
342
|
+
accuracy: accuracy_ios,
|
|
343
|
+
priority: priority_android,
|
|
344
|
+
interval
|
|
334
345
|
});
|
|
335
346
|
};
|
|
336
347
|
this.stop = function () {
|
|
337
348
|
window.natively.trigger(id, 3, undefined, "location_stop", {});
|
|
338
349
|
};
|
|
350
|
+
this.startBackground = function (interval, accuracy_ios, priority_android, responseIdentifier, location_bg_callback) {
|
|
351
|
+
const params = {};
|
|
352
|
+
params.identifier = typeof responseIdentifier === "undefined" ? "empty" : responseIdentifier;
|
|
353
|
+
params.interval = typeof interval === "undefined" ? 1000 * 60 : interval;
|
|
354
|
+
params.accuracy = typeof accuracy_ios === "undefined" ? 50 : accuracy_ios;
|
|
355
|
+
params.priority = typeof priority_android === "undefined" ? "BALANCED" : priority_android;
|
|
356
|
+
window.natively.trigger(id, 4, location_bg_callback, "location_start_bg", params);
|
|
357
|
+
};
|
|
358
|
+
this.stopBackground = function (location_bg_callback) {
|
|
359
|
+
window.natively.trigger(id, 4, location_bg_callback, "location_stop_bg", {});
|
|
360
|
+
};
|
|
339
361
|
}
|
|
340
362
|
}
|
|
341
363
|
|
package/natively-frontend.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function generateID(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}window.natively={isDebug:!1,min_app_version:0,app_version:0,injected:!1,observers:[],setDebug:function(e){window.natively.isDebug=e},notify:function(e,
|
|
1
|
+
function generateID(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}window.natively={isDebug:!1,min_app_version:0,app_version:0,injected:!1,observers:[],setDebug:function(e){window.natively.isDebug=e},notify:function(e,i){window.natively.injected=!0,e&&(window.natively.min_app_version=e),i&&(window.natively.app_version=i);const t=window.natively.observers;for(natively.isDebug&&console.log("[INFO] Notify observers: ",t.length);t.length>0;){const e=t.shift();e()}},addObserver:function(e){window.natively.injected?e():(window.natively.isDebug&&console.log(`[DEBUG] addObserver: ${e}`),window.natively.observers.push(e))},trigger:function(e,i,t,n,o){const r=window.natively.isDebug;if(window.natively.injected)if(i>window.natively.app_version)r&&alert(`[ERROR] Please rebuild the app to use this functionality. App Version: ${window.natively.app_version}, feature version: ${i}`);else{if(t){let i;i=e?n+"_response_"+e:n+"_response",window[i]=function(n,o){$agent.response(),o.message&&r?alert(`[ERROR] Error message: ${o.message}`):(r&&console.log(`[DEBUG] Callback method: ${i}, body: ${JSON.stringify(n)}, respId: ${e}`),t(n))},o?o.response_id=e:o={response_id:e}}r&&console.log(`[DEBUG] Trigger method: ${n}, body: ${JSON.stringify(o)}`),$agent.trigger(n,o)}else window.natively.addObserver(()=>{window.natively.trigger(e,i,t,n,o)})},shareImage(e){window.natively.trigger(void 0,0,void 0,"share_image",{url:e})},shareText(e){window.natively.trigger(void 0,0,void 0,"share_text",{text:e})},shareTextAndImage(e,i){window.natively.trigger(void 0,0,void 0,"share_text_and_image",{url:i,text:e})},shareFile(e){window.natively.trigger(void 0,2,void 0,"share_file",{url:e})},openExternalURL(e){window.natively.trigger(void 0,0,void 0,"open_link",{url:e})},openExternalAppIOS(e){window.natively.trigger(void 0,0,void 0,"open_app",{url:e})},openAppSettings(){window.natively.trigger(void 0,0,void 0,"open_appsettings")},showAppToast(e,i){const t={};t.text=void 0===i?"":i,t.type=void 0===e?"DEFAULT":e,window.natively.trigger(void 0,0,void 0,"show_toast",t)},showAppBanner(e,i,t){const n={};n.type=void 0===e?"INFO":e,n.title=void 0===i?"":i,n.description=void 0===t?"":t,window.natively.trigger(void 0,0,void 0,"show_banner",n)},requestAppReview(){window.natively.trigger(void 0,0,void 0,"request_review")},setAppBackgroundColor(e){const i={color:e};window.natively.trigger(void 0,1,void 0,"app_background",i)},setAppProgressColor(e){const i={color:e};window.natively.trigger(void 0,1,void 0,"app_progress",i)},setAppSwipeNavigationIOS(e){const i={toggle:e};window.natively.trigger(void 0,1,void 0,"app_navigation",i)},setAppPullToRefresh(e){const i={toggle:e};window.natively.trigger(void 0,1,void 0,"app_pull",i)},setAppOrientation(e){const i={orientation:e};window.natively.trigger(void 0,3,void 0,"app_orientation",i)},setAppStatusBarStyleIOS(e){const i={style:e};window.natively.trigger(void 0,2,void 0,"status_bar_style",i)},async sendPushNotification(e,i,t,n){const o=t.filter(e=>e.length>0),r=[...new Set(o)];let s={app_id:n?"be83022a-1d08-45d0-a07a-0c3655666e17":e,include_player_ids:r};i.template_id?s.template_id=i.template_id:(s.headings={},s.headings.en=i.title||"Empty Title",s.contents={},s.contents.en=i.message||"Empty Message",i.subtitle&&(s.subtitle={},s.subtitle.en=i.subtitle),i.redirect_url&&(s.url=i.redirect_url));const a={method:"POST",headers:{"Content-type":"application/json"},body:JSON.stringify(s)};return await fetch("https://onesignal.com/api/v1/notifications",a)}},window.natively.addObserver(()=>window.natively.trigger(void 0,0,e=>{window.natively.min_app_version=e.minSDKVersion,window.natively.app_version=e.sdkVersion},"app_info",{}));class NativelyInfo{constructor(){const e=generateID();this.browserInfo=function(){const e=void 0!==typeof $agent,i=window.navigator.userAgent.includes("Natively/iOS"),t=window.navigator.userAgent.includes("Natively/Android");return{isNativeApp:e,isIOSApp:i,isAndroidApp:t}},this.getAppInfo=function(i){window.natively.trigger(e,0,i,"app_info")},this.connectivity=function(e){window.natively.trigger(void 0,0,e,"connectivity")}}}class NativelyPagesCache{constructor(){const e=generateID();this.currentPageCached=function(i){window.natively.trigger(e,4,i,"current_page_cached")},this.storeCurrentPage=function(i){window.natively.trigger(e,4,i,"store_current_page")},this.resetCurrentPage=function(i){window.natively.trigger(e,4,i,"reset_current_page")},this.resetAll=function(i){window.natively.trigger(e,4,i,"reset_all")}}}class NativelyNotifications{constructor(){const e=generateID();this.getOneSignalId=function(i){window.natively.trigger(e,0,i,"onesignal_playerid")},this.requestPermission=function(i,t){window.natively.trigger(e,0,t,"push_register",{fallbackToSettings:i})},this.getPermissionStatus=function(i){window.natively.trigger(e,0,i,"push_permission")}}}class NativelyGeolocation{constructor(){const e=generateID();this.getUserGeolocation=function(i,t){window.natively.trigger(e,0,t,"geolocation",{distance:i})},this.requestPermission=function(i){window.natively.trigger(e,0,i,"geo_register")},this.getPermissionStatus=function(i){window.natively.trigger(e,0,i,"geo_permission")}}}class NativelyLocation{constructor(){const e=generateID();this.current=function(i,t,n){window.natively.trigger(e,3,n,"location_current",{accuracy:i,priority:t})},this.start=function(i,t,n,o){window.natively.trigger(e,3,o,"location_start",{accuracy:t,priority:n,interval:i})},this.stop=function(){window.natively.trigger(e,3,void 0,"location_stop",{})},this.startBackground=function(i,t,n,o,r){const s={};s.identifier=void 0===o?"empty":o,s.interval=void 0===i?6e4:i,s.accuracy=void 0===t?50:t,s.priority=void 0===n?"BALANCED":n,window.natively.trigger(e,4,r,"location_start_bg",s)},this.stopBackground=function(i){window.natively.trigger(e,4,i,"location_stop_bg",{})}}}class NativelyMessage{constructor(){const e=generateID();this.sendSMS=function(i,t,n){const o={};o.body=void 0===i?"":i,o.recipient=void 0===t?"":t,window.natively.trigger(e,0,n,"send_sms",o)},this.sendEmail=function(i,t,n,o){const r={};r.subject=void 0===i?"":i,r.body=void 0===t?"":t,r.recipient=void 0===n?"":n,window.natively.trigger(e,0,o,"send_email",r)}}}class NativelyStorage{constructor(){const e=generateID();this.setStorageValue=function(i,t){window.natively.trigger(e,0,void 0,"set_storage_value",{key:i,value:t})},this.getStorageValue=function(i,t){window.natively.trigger(e,0,t,"get_storage_value",{key:i})},this.removeStorageValue=function(i){window.natively.trigger(e,0,void 0,"remove_storage_value",{key:i})},this.resetStorage=function(){window.natively.trigger(e,0,void 0,"reset_storage")}}}class NativelyBiometrics{constructor(e){this.allowPass=e;const i=generateID();this.checkBiometricsSupport=function(t){window.natively.trigger(i,0,t,"biometrics_support",{allowPass:e})},this.checkCredentials=function(e){window.natively.trigger(i,0,e,"biometrics_has_credentials")},this.verifyUserIdentify=function(t){window.natively.trigger(i,0,t,"biometrics_verify",{allowPass:e})},this.getUserCredentials=function(t){window.natively.trigger(i,0,t,"biometrics_auth",{allowPass:e})},this.removeUserCredentials=function(e){window.natively.trigger(i,0,e,"biometrics_remove_credentials")},this.saveUserCredentials=function(t,n,o){window.natively.trigger(i,0,o,"biometrics_auth",{allowPass:e,login:t,password:n})}}}class NativelyDatePicker{constructor(){const e=generateID();this.showDatePicker=function(i,t,n,o,r){let s={};s.type=void 0===n?"DATE":n,s.style=void 0===o?"LIGHT":o,s.title=void 0===i?"":i,s.description=void 0===t?"":t,window.natively.trigger(e,0,r,"datepicker",s)}}}class NativelyCamera{constructor(){const e=generateID();this.showCamera=function(i,t,n){let o={};o.type=void 0===i?"photo":i,o.quality=void 0===t?"high":t,window.natively.trigger(e,2,n,"open_camera",o)}}}class NativelyScanner{constructor(){const e=generateID();this.showScanner=function(i){window.natively.trigger(e,2,i,"open_scanner",{})}}}class NativelyPurchases{constructor(){const e=generateID();this.login=function(i,t){window.natively.trigger(e,3,t,"purchases_login",{login:i})},this.logout=function(i){window.natively.trigger(e,3,i,"purchases_logout",{})},this.customerId=function(i){window.natively.trigger(e,3,i,"purchases_customerid",{})},this.purchasePackage=function(i,t){window.natively.trigger(e,3,t,"purchases_package",{packageId:i})}}}class NativelyContacts{constructor(){const e=generateID();this.getAllContacts=function(i){window.natively.trigger(e,3,i,"contacts_all",{})},this.createContact=function(i,t,n,o,r){let s={firstName:i};s.lastName=void 0===t?"":t,s.email=void 0===n?"":n,s.phone=void 0===o?"":o,window.natively.trigger(e,3,r,"contacts_save",s)}}}
|