forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.ios.ts
More file actions
151 lines (123 loc) · 4.8 KB
/
application.ios.ts
File metadata and controls
151 lines (123 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import appModule = require("application/application-common");
import frame = require("ui/frame");
import utils = require("utils/utils");
import types = require("utils/types");
import view = require("ui/core/view");
import definition = require("application");
// merge the exports of the application_common file with the exports of this file
declare var exports;
require("utils/module-merge").merge(appModule, exports);
export var mainModule: string;
class Window extends UIWindow {
private _content: view.View;
initWithFrame(frame: CGRect): UIWindow {
var window = super.initWithFrame(frame);
if (window) {
window.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;
}
return window;
}
public get content(): view.View {
return this._content;
}
public set content(value: view.View) {
this._content = value;
}
public layoutSubviews(): void {
utils.ios._layoutRootView(this._content);
}
}
class TNSAppDelegate extends UIResponder implements UIApplicationDelegate {
// An array of protocols to be implemented by the native class
public static ObjCProtocols = [UIApplicationDelegate];
public window: Window;
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {
this.window = <Window>Window.alloc().initWithFrame(UIScreen.mainScreen().bounds);
this.window.backgroundColor = UIColor.whiteColor();
if (exports.onLaunch) {
exports.onLaunch();
}
var topFrame = frame.topmost();
if (!topFrame) {
if (mainModule) {
topFrame = new frame.Frame();
topFrame.navigate(mainModule);
} else {
// TODO: Throw an exception?
// throw new Error("A Frame must be used to navigate to a Page.");
return;
}
}
this.window.content = topFrame;
this.window.rootViewController = topFrame.ios.controller;
var app: IOSApplication = exports.ios;
app.rootController = this.window.rootViewController;
this.window.makeKeyAndVisible();
return true;
}
applicationDidBecomeActive(application: UIApplication) {
if (exports.onResume) {
exports.onResume();
}
}
applicationWillResignActive(application: UIApplication) {
//
}
applicationDidEnterBackground(application: UIApplication) {
if (exports.onSuspend) {
exports.onSuspend();
}
}
applicationWillEnterForeground(application: UIApplication) {
//
}
applicationWillTerminate(application: UIApplication) {
if (exports.onExit) {
exports.onExit();
}
}
applicationDidReceiveMemoryWarning(application: UIApplication) {
if (exports.onLowMemory) {
exports.onLowMemory();
}
}
applicationOpenURLSourceApplicationAnnotation(application: UIApplication, url: NSURL, sourceApplication: string, annotation: any): boolean {
var dictionary = new NSMutableDictionary();
dictionary.setObjectForKey(url, "TLKApplicationOpenURL");
dictionary.setObjectForKey(application, "TLKApplication");
NSNotificationCenter.defaultCenter().postNotificationNameObjectUserInfo("com.telerik.TLKApplicationOpenURL", null, dictionary);
return true; // or should we return false???
}
}
class IOSApplication implements definition.iOSApplication {
public nativeApp: any;
public rootController: any;
private _tnsAppdelegate: TNSAppDelegate;
constructor() {
// TODO: in iOS there is the singleton instance, while in Android such does not exist hence we pass it as argument
this.nativeApp = UIApplication.sharedApplication();
}
public init() {
this._tnsAppdelegate = new TNSAppDelegate();
}
}
// TODO: If we have nested require(application) calls we may enter unfinished module state, which will create two delegates, resulting in an exception
var app = new IOSApplication();
exports.ios = app;
app.init();
exports.start = function () {
appModule.loadCss();
try {
// The "UIApplicationMain" enters a modal loop and the call will not return while the application is running.
// This try-catch block here will catch JavaScript errors but no Objective C ones.
// TODO: We need to implement better error handling for our native calls and to use the "error" parameter of the iOS APIs.
UIApplicationMain(0, null, null, "TNSAppDelegate");
}
catch (error) {
// At this point the main application loop is exited and no UI May be created.
if (!types.isFunction(exports.onUncaughtError)) {
return;
}
exports.onUncaughtError(error);
}
}