Creating [object] in a different context than the calling function.
On 19 August 2016 in TechCreating [object] in a different context than the calling function.
This warning occured when a JS callback function is passed to Objective-C as KrollCallback and then executed on non-JS thread.
KrollCallback *callback = [args [email protected]"callback"]; [OneSignal initWithLaunchOptions:[TiApp app].launchOptions appId:appId handleNotificationAction:^(OSNotificationResult *result) { [callback call:@[] thisObject:nil]; }];
Problem with this warning is, if the JS callback create Ti.Network.HTTPClient instance, then that instance is null.
function callback() { var http = Ti.Network.createHTTPClient(); http.open('GET', getUrl()); // JS error! http is null http.send(); }
To fix, get krollContext instance of current module/proxy and execute callback inside invokeBlockOnThread
// For TiModule / TiProxy descendants KrollContext *context = [self.executionContext krollContext]; // For TiUIView descendants KrollContext *context = [self.proxy.executionContext krollContext]; // invoke [context invokeBlockOnThread:^{ [callback call:@[] thisObject:nil]; }];
Related posts:
-
codesign failed: resource fork, Finder information, or similar detritus not allowed
-
Update iOS Titanium module SDK version
-
iOS simulator folder
-
iOS screen size
-
Titanium app hex color value with alpha channel
-
Use view from custom module inside Titanium ListViewItem
-
Setup Titanium Studio environment for developing Titanium module (Android) on Windows
-
Titanium iOS “build” is an unrecognized command
-
Add custom framework to Titanium iOS module
-
Load nib file in Titanium module iOS
Filed under Tech with tags iOS, Javascript, Objective C, Titanium Mobile
Leave a Reply