Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//// Add custom application delegate
if (app.ios) {
class MyDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {
return true;
}
applicationDidBecomeActive(application: UIApplication): void {
// Get reference to the application window.
//console.log("keyWindow: " + application.keyWindow);
}
}
app.ios.delegate = MyDelegate;
}
// << application-ios-delegate
export function testIOSApplicationInitialized() {
TKUnit.assert(app.ios, "iOS application not initialized.");
TKUnit.assert(app.ios.delegate, "iOS delegate not initialized.");
TKUnit.assert(app.ios.nativeApp, "iOS nativeApp not initialized.");
TKUnit.assert(app.ios.orientation, "iOS orientation not initialized.");
TKUnit.assert(app.ios.window, "iOS window not initialized.");
TKUnit.assert(app.ios.rootController, "iOS root controller not initialized.");
}
app.on(app.lowMemoryEvent, (args: app.ApplicationEventData) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log('Activity: ' + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log('UIApplication: ' + args.ios);
}
});
app.on(app.uncaughtErrorEvent, (args: app.UnhandledErrorEventData) => {
console.log('Error: ' + args.error);
});
if (app.ios != null) {
class BitwardenApplicationDelegate extends UIResponder implements UIApplicationDelegate {
static ObjCProtocols = [UIApplicationDelegate];
static serviceContainer: ServiceContainer = null;
applicationDidFinishLaunchingWithOptions(application: UIApplication,
launchOptions: NSDictionary): boolean {
console.log('applicationWillFinishLaunchingWithOptions: ' + launchOptions);
BitwardenApplicationDelegate.serviceContainer = new ServiceContainer();
BitwardenApplicationDelegate.serviceContainer.init();
BitwardenApplicationDelegate.serviceContainer.bootstrap();
appMain.init();
return true;
}
applicationDidBecomeActive(application: UIApplication): void {
console.log('applicationDidBecomeActive: ' + application);
export function setStatusBarColors() {
// Make the iOS status bar transparent with white text
if (application.ios) {
application.on("launch", () => UIApplication.sharedApplication.setStatusBarStyleAnimated(UIStatusBarStyle.LightContent, true));
}
// Make the Android status bar transparent
if (application.android) {
// TODO make sure this works when --uglify'd, otherwise use "activityStarted"
application.android.on(application.AndroidApplication.activityStartedEvent, (data: application.AndroidActivityEventData) => {
if (application.android && device.sdkVersion >= "21") {
let View = android.view.View;
let window = application.android.startActivity.getWindow();
window.setStatusBarColor(0x000000);
let decorView = window.getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
import { AppModule } from "./app.module";
import * as application from 'tns-core-modules/application';
import { AppCenterSettings, AppCenter } from "nativescript-microsoft-appcenter";
if (application.ios){
let appCenterSettings: AppCenterSettings = {
appSecret: "",
analytics: true,
crashes: true,
distribute: true,
}
let appCenter = new AppCenter();
appCenter.startWithAppDelegate(appCenterSettings);
}
platformNativeScriptDynamic().bootstrapModule(AppModule);
videoPlayer = AVPlayer.playerWithURL(nativeUrl);
} else {
if (video instanceof AVPlayer) {
videoPlayer = video;
} else if (video.ios && video.ios instanceof AVPlayer) {
videoPlayer = video.ios;
}
}
materialPlane.firstMaterial.diffuse.contents = videoPlayer;
materialPlane.firstMaterial.doubleSided = true;
if (options.loop !== false) {
const AVPlayerItemDidPlayToEndTimeNotificationObserver = application.ios.addNotificationObserver(
AVPlayerItemDidPlayToEndTimeNotification,
(notification: NSNotification) => {
// const player = this.plane.firstMaterial.diffuse.contents;
if (videoPlayer.currentItem && videoPlayer.currentItem === notification.object) {
videoPlayer.seekToTime(CMTimeMake(5, 100));
videoPlayer.play();
}
}
);
}
if (options.play !== false) {
videoPlayer.play();
}
const node = SCNNode.nodeWithGeometry(materialPlane);
// node.addAudioPlayer(SCNAudioPlayer);
export function waitUntilReady(isReady: () => boolean, timeoutSec: number = 3, shouldThrow: boolean = true) {
if (!isReady) {
return;
}
if (Application.ios) {
const timeoutMs = timeoutSec * 1000;
let totalWaitTime = 0;
while (true) {
const begin = time();
const currentRunLoop = utils.ios.getter(NSRunLoop, NSRunLoop.currentRunLoop);
currentRunLoop.limitDateForMode(currentRunLoop.currentMode);
if (isReady()) {
break;
}
totalWaitTime += time() - begin;
if (totalWaitTime >= timeoutMs) {
if (shouldThrow) {
throw new Error("waitUntilReady Timeout.");
} else {
break;
ngOnInit() {
this.checkForceUpdate();
if (application.ios && application.ios.window.safeAreaInsets) {
const bottomSafeArea: number = application.ios.window.safeAreaInsets.bottom;
console.log('safe are<>', bottomSafeArea);
this.bottomSafeArea = bottomSafeArea > 0 ? this.bottomSafeArea + bottomSafeArea : this.bottomSafeArea;
}
firebase.init({
onMessageReceivedCallback: (message) => {
console.log('message', message);
if (message.foreground) {
this.utils.showMessage('success', message.body);
}
this.ngZone.run(() => this.navigationService.redirectPushRoutes(message.data));
},
showNotifications: true,
showNotificationsWhenInForeground: true
}).then(
() => {
private getPictureResourcePath(groupName: string, exampleName: string) {
if (app.ios) {
return "res://chart/" + groupName + "/" + exampleName;
}
var resourcePath = "res://" + exampleName;
return resourcePath;
}
if (this.controls !== false) {
this._playerController.showsPlaybackControls = true;
}
this._playerController.player = this._player;
if (isNaN(this.width) || isNaN(this.height)) {
this.requestLayout();
}
if (this.muted === true) {
this._player.muted = true;
}
if (!this._didPlayToEndTimeActive) {
this._didPlayToEndTimeObserver = application.ios.addNotificationObserver(
AVPlayerItemDidPlayToEndTimeNotification,
this.AVPlayerItemDidPlayToEndTimeNotification.bind(this)
);
this._didPlayToEndTimeActive = true;
}
}
public startWithAppDelegate(settings: AppCenterSettings): void {
AppCenterDelegate.setup(settings);
application.ios.delegate = AppCenterDelegate;
}