Time for action – add an iOS fix for the Android menu
Here is how to fix the Android menu problem on iOS:
Add the following function to
app.js
:function isAndroid() { return (Ti.Platform.name == 'android'); }
Wrap the
addMenu
function where our platform-specific code lies with this code:function addMenu(win) { if (isAndroid()) { var activity = win.activity; activity.onCreateOptionsMenu = function(e){ var firstItem = e.menu.add({ title: 'First Item' }); firstItem.addEventListener("click", function(e) {Ti.API.debug('First Item'); }); var secondItem = e.menu.add({ title: 'Second Item'}); secondItem.addEventListener("click", function(e) {Ti.API.warn('Second Item'); }); var thirdItem = e.menu.add({ title: 'Third Item'}); thirdItem.addEventListener("click", function(e) {alert('Third Item'); }); } }; }
Run the app on the iOS emulator.
What just happened?
An if
statement was added that ensured that if the app was run on iOS, a menu would not...