[AC-6561] Ti.Platform.openURL causes "undefined is not an object" error
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2020-07-20T14:16:18.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | ios |
Reporter | Justin Toth |
Assignee | Christopher Williams |
Created | 2020-06-18T00:29:50.000+0000 |
Updated | 2020-07-20T14:16:19.000+0000 |
Description
When launching any url with Ti.Platform.openURL on iOS, the app then throws this error:
[ERROR] Script Error {
[ERROR] message = "undefined is not an object";
[ERROR] type = TypeError;
[ERROR] }
It does not provide a stack trace, which is a separate issue. The interesting thing is that it will actually execute the openURL command but then when you return to your Titanium app and execute any subsequent Titanium code, it throws the error.
Another user has reported this same issue on [SO](https://stackoverflow.com/questions/62328830/getting-error-after-openurl-on-appcelerator-titanium-v-9), so I do not believe this issue is specific to our app.
Below is a simple repro. Launch the app then wait 10 seconds and notice how it correctly opens the apple maps url. Return to the Titanium app and wait another 10 seconds, and notice how the second openURL errors. The second openURL isn't relevant, what is relevant is that Titanium code has executed after the first openURL, and that's enough to cause it to error.
var win = Ti.UI.createWindow({
title: 'Ti.Platform.openURL Bug'
});
win.open();
var button = Ti.UI.createButton({
top: 100,
height: Ti.UI.SIZE,
title: 'Open maps'
});
button.addEventListener('click', function() {
Ti.Platform.openURL('http://maps.apple.com/maps?q=-8.012960,110.308998');
});
win.add(button);
setInterval(function() {
Ti.Platform.openURL('http://maps.apple.com/maps?q=-8.012960,110.308998');
}, 10000);
Also of note, I'm not confident that the interval is the ONLY way to cause this error, as I get this error even executing openURL commands not in an interval, but it certainly is easier to reproduce if it is within an interval.
This bug exists in Ti SDK 9.0.0+. Ti SDK 8.3.1.GA is the newest version that doesn't have this bug.
I found a workaround for now from another ticket, specifying the second and third args of openURL:
Workaround works fine! I had the same error opening a external URL in 9.0.3.GA
Resolved as duplicate of linked ticket. Fix was just pushed to master/9_1_X/9_3_X. Release 9.1.0 will contain it. (or if you really need the fix and don't want to use the empty function callback workaround, you should be able to install a new 9_0_X branch build via
ti sdk install -b. 9_0_X
in about an hour once the build goes out)