Merge pull request #897 from NativeScript/atanasovg/ios-uncaughtError

Integrate recent iOS Runtime global.__onUncaughtError feature
This commit is contained in:
Vladimir Enchev
2015-10-12 11:52:10 +03:00
2 changed files with 14 additions and 30 deletions

View File

@ -301,19 +301,12 @@ class BroadcastReceiver extends android.content.BroadcastReceiver {
}
global.__onUncaughtError = function (error: Error) {
if (!types.isFunction(exports.onUncaughtError)) {
return;
// TODO: Obsolete this
if (types.isFunction(exports.onUncaughtError)) {
exports.onUncaughtError(error);
}
var nsError = {
message: error.message,
name: error.name,
nativeError: (<any>error).nativeException
}
exports.onUncaughtError(nsError);
exports.notify({ eventName: dts.uncaughtErrorEvent, object: appModule.android, android: nsError });
exports.notify({ eventName: dts.uncaughtErrorEvent, object: appModule.android, android: error });
}
exports.start = function () {

View File

@ -208,25 +208,16 @@ class IOSApplication implements definition.iOSApplication {
var iosApp = new IOSApplication();
exports.ios = iosApp;
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, exports.ios && exports.ios.delegate ? NSStringFromClass(exports.ios.delegate) : NSStringFromClass(Responder));
}
catch (error) {
// At this point the main application loop is exited and no UI May be created.
if (!types.isFunction(exports.onUncaughtError)) {
return;
}
global.__onUncaughtError = function (error: Error) {
// TODO: This should be obsoleted
if (types.isFunction(exports.onUncaughtError)) {
exports.onUncaughtError(error);
}
definition.notify({ eventName: definition.uncaughtErrorEvent, object: <any>definition.ios, ios: error });
}
exports.start = function () {
appModule.loadCss();
UIApplicationMain(0, null, null, exports.ios && exports.ios.delegate ? NSStringFromClass(exports.ios.delegate) : NSStringFromClass(Responder));
}