forked from timanrebel/HockeyApp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catching UIApplicationMain exceptions
Implemented a Ti build plugin and extended the module in order to catch and report the description of exceptions in UIApplicationMain. The plugin adds some wrapping code to the main.m file automatically generated by Titanium, which, when an exception is catch, records its description to NSUserDefaults. That value is picked up by HockeyApp at the next app start, and it’s used for augmenting the crash report.
- Loading branch information
Showing
7 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
54911 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
exports.cliVersion = '>=3.X'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
|
||
var UIApplicationMainStatement = ' int retVal = UIApplicationMain(argc, argv, nil, @"TiApp");'; | ||
|
||
var replacementRows = [ | ||
' int retVal = 0;', | ||
' @try {\n', | ||
' retVal = UIApplicationMain(argc, argv, nil, @"TiApp");', | ||
' }', | ||
' @catch (NSException *e) {', | ||
' //we save the exception description to NSUserDefaults, this value will be picked up at next app start by hockeyapp', | ||
' [[NSUserDefaults standardUserDefaults] setObject:e.description forKey:[NSString stringWithFormat:@"%@.%@", TI_APPLICATION_ID, @"crash_info"]];', | ||
' [[NSUserDefaults standardUserDefaults] synchronize];', | ||
' //we need to crash here anyway for hockeyapp to notice', | ||
' @throw e;', | ||
' }'].join("\n"); | ||
|
||
|
||
|
||
exports.init = function(logger, config, cli, appc) { | ||
if (cli.argv.platform != 'android') { | ||
|
||
cli.addHook('build.pre.compile', function(build, finished) { | ||
logger.info('Replacing the populateIosFiles() function in the iOS Build plugin'); | ||
var populateIosFiles = build.populateIosFiles; | ||
if (populateIosFiles) { | ||
build.populateIosFiles = function() { | ||
|
||
var result = populateIosFiles.call(build); | ||
|
||
var mainFile = path.join(this.buildDir, 'main.m'); | ||
var mainContents = fs.readFileSync(mainFile); | ||
if (!mainContents) { | ||
logger.error('Cannot find main.m in build dir'); | ||
process.exit(1); | ||
} else { | ||
var mainContentsStr = mainContents.toString(); | ||
var uiAppMainInvocationMatch = mainContentsStr.match(/UIApplicationMain\(argc,\sargv,\snil,\s\@\"TiApp\"\)/g); | ||
if (!uiAppMainInvocationMatch) { | ||
logger.error('Cannot find UIApplicationMain invocation'); | ||
process.exit(1); | ||
} | ||
//we inject the AppConnectUIApplication UIApplication subclass | ||
logger.info('Modifying UIApplicationMain invocation in the generated main.m'); | ||
mainContentsStr = mainContentsStr.replace(UIApplicationMainStatement, replacementRows); | ||
fs.writeFileSync(mainFile, mainContentsStr); | ||
} | ||
|
||
return result; | ||
}; | ||
} else { | ||
logger.error('Can\'t inject hook into ios build'); | ||
process.exit(1); | ||
} | ||
finished(); | ||
}); | ||
} | ||
}; |
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