Created
October 27, 2020 10:43
-
-
Save Sunilkumarr/070ce52a982e40b474cc1ec89ff7b1f6 to your computer and use it in GitHub Desktop.
app.ts for activate or deactivate NS7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In NativeScript, the app.ts file is the entry point to your application. | |
You can use this file to perform app-level initialization, but the primary | |
purpose of the file is to pass control to the app’s first module. | |
*/ | |
import { Application, Utils } from '@nativescript/core'; | |
/// START APPLOZIC NativeScript | |
let launchListener; | |
let exitListener; | |
let broadcastManager: any = null; | |
declare const global: any; | |
declare const android: any; | |
let broadcastManagerReceivedCallback = undefined; | |
/// END APPLOZIC NativeScript | |
Application.run({ moduleName: 'app-root' }); | |
/* | |
Do not place any code after the application has been started as it will not | |
be executed on iOS. | |
*/ | |
/// START APPLOZIC NativeScript | |
launchListener = (args) => { | |
if (Application.android != undefined) { | |
broadcastManager = global.androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(Utils.ad.getApplicationContext()); | |
console.log("We are running on Android device!"); | |
const cb = android.content.BroadcastReceiver.extend({ | |
onReceive: (context, data) => { | |
if (data != null) { | |
if (data.getAction() == "USER_ACTIVATED") { | |
console.log("Login user ACTIVATED on Android device!"); | |
} else if (data.getAction() == "USER_DEACTIVATED") { | |
console.log("Login user DEACTIVATED on Android device!"); | |
} | |
} | |
} | |
}); | |
broadcastManagerReceivedCallback = new cb(); | |
broadcastManager.registerReceiver(broadcastManagerReceivedCallback, new android.content.IntentFilter("USER_ACTIVATED")); | |
broadcastManager.registerReceiver(broadcastManagerReceivedCallback, new android.content.IntentFilter("USER_DEACTIVATED")); | |
} else if (Application.ios) { | |
Application.ios.addNotificationObserver("ALLoggedInUserDidChangeDeactivateNotification", (notification) => { | |
const userInfo = notification.userInfo as NSDictionary<any, any>; | |
if (userInfo != null) { | |
if (userInfo.valueForKey("DEACTIVATED") == "true") { | |
console.log("Login USER is Deactivited"); | |
} else{ | |
console.log("Login USER is activited"); | |
} | |
} | |
}); | |
} | |
}; | |
Application.on(Application.launchEvent, launchListener); | |
exitListener = (args) => { | |
if (Application.android != undefined) { | |
if (broadcastManagerReceivedCallback != undefined && broadcastManager != null){ | |
broadcastManager.unregisterReceiver(broadcastManagerReceivedCallback); | |
broadcastManagerReceivedCallback = undefined; | |
} | |
} | |
}; | |
Application.on(Application.exitEvent, exitListener); | |
/// END APPLOZIC NativeScript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment