Ti.Platform.osname not working

You must Login before you can answer or comment on any questions.

Hi ,

I tried the following code , but whenever i try to run the code on iPad its not showing anything..but on iPhone its working fine. The alerts are also not coming. I am using 2.1.1 as titanium sdk

app.js

if (Ti.Platform.osname == 'ipad') {
 
alert('ipad')
 
var ipad_win1=Ti.UI.createWindow({
    navBarHidden:true,
    backgroundImage:'pics/about_ipad.png'
});
 
ipad_win1.open();
}
 
else{
 
    alert('iphone')
 
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
 
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
 
 
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    backgroundImage:'pics/about_iphone.png',
    navBarHidden:true
});
var tab1 = Titanium.UI.createTab({  
    icon:'pics/about.png',
    title:'About',
    window:win1
});
 
 
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    navBarHidden:true,
    backgroundImage:'pics/bg_iphone.png'
});
 
var tab2 = Titanium.UI.createTab({  
    icon:'pics/movie.png',
    title:'Video',
    window:win2
});
 
////
//
//  add tabs
//
tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  
 
// open tab group
tabGroup.open();
}

2 Answers

Hi Mathew

When in the iPad mode you have asked it to create a window and open in outside of the tabGroup - it will not slide the current window to the left showing this coming in from the right.

But you need to add one more parameter to get it to display in the way I think you want it.

var ipad_win1 = Ti.UI.createWindow({
    navBarHidden: true,
    modal: true, // this one
    backgroundImage: 'pics/about_ipad.png'
});
By adding the modal window it shows the window over the top of the tabGroup.

Please note you will need some way of closing it of course.

Try that and let me know.

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
9 Comments
  • No not working..

    — commented 10 months ago by mathew orleans

  • even if i copy paste the whole code of iPhone in the if loop , it doesn't work...and just shows the splash screen on the iPad nothing else.

    — commented 10 months ago by mathew orleans

  • I may have misread your question earlier, I thought you were having problems displaying the window used in the ipad section - rather than it not appearing to display at all.

    Try this code (below) - is your code with a few tweaks - nothing fundamental - just re-order non-essential bits.

    I have however added a label to each window that appears, one for the ipad and one each for the two windows on the iPhone.

    I have no problems getting this code to show the single window for iPad or the two windows for the iPhone.

    Your code is asking that if running on an;

    1. iPad - show ONLY ONE window and no tabs.
    2. iPhone - show TWO tabs each with their own window.

    Plus my labels.

    // this sets the background color of the master UIView (when there are no windows/tab groups on it)
    Ti.UI.setBackgroundColor('#000');
     
    if (Ti.Platform.osname === 'ipad') {
        alert('ipad')
     
        var ipad_win1 = Ti.UI.createWindow({
            navBarHidden: true,
            backgroundImage:'pics/about_ipad.png'
        });
     
        var lbliPad = Ti.UI.createLabel({
            color: 'red',
            font: {
                fontSize: 36
            },
            height: Ti.UI.SIZE,
            text: 'iPad',
            width: Ti.UI.SIZE
        });
        ipad_win1.add(lbliPad);
     
        ipad_win1.open();
     
    } else {
        alert('iphone')
     
     
        var win1 = Ti.UI.createWindow({  
            backgroundImage: 'pics/about_iphone.png',
            navBarHidden: true
        });
        var tab1 = Ti.UI.createTab({  
            icon: 'pics/about.png',
            title: 'About',
            window: win1
        });
        var lbl1 = Ti.UI.createLabel({
            color: 'red',
            font: {
                fontSize: 36
            },
            height: Ti.UI.SIZE,
            text: 'iPhone Window 1',
            width: Ti.UI.SIZE
        });
        win1.add(lbl1);
     
        var win2 = Ti.UI.createWindow({  
            navBarHidden: true,
            backgroundImage: 'pics/bg_iphone.png'
        });
        var tab2 = Ti.UI.createTab({  
            icon: 'pics/movie.png',
            title: 'Video',
            window: win2
        });
        var lbl2 = Ti.UI.createLabel({
            color: 'red',
            font: {
                fontSize: 36
            },
            height: Ti.UI.SIZE,
            text: 'iPhone Window 2',
            width: Ti.UI.SIZE
        });
        win2.add(lbl2);
     
        var tabGroup = Ti.UI.createTabGroup();
     
        tabGroup.addTab(tab1);  
        tabGroup.addTab(tab2);  
     
        tabGroup.open();
    }
    What happens here?

    BTW I removed my previous the modal line as it was irrelevant.

    — commented 10 months ago by Malcolm Hollingsworth

  • Show 6 more comments

Or, totally ignore everything and use alert(Ti.Platform.osname)

If you get something, you know it works and your code doesn't.

Your Answer

Think you can help? Login to answer this question!