Sunday, September 26, 2010

Titanium Titanium.App.Properties problem

Here is another case where in Titanium the iPhone simulator successfully runs a feature that fails on the iPhone. In this case its the Titanium.App.Properties. This is supposed you allow you save global variables. From the documentation, you set it up like this:

Save variable:
Titanium.App.Properties.setString("myVar","myValue");

Retrieve variable:
Titanium.App.Properties.getString("myVar"); '// returns "myValue"

This works fine on the simulator but fails on the iPhone unless you follow two additional steps:

1. From the Kitchen Sink project -- copy /modules/iphone/settings.bundle
2. Create a /modules/iphone folder in your project and paste the settings.bundle file there
3. Make sure to name all your variables with a "_preference" suffix. So our examples above should be:

Save variable:
Titanium.App.Properties.setString("myVar_preference","myValue");

Retrieve variable:
Titanium.App.Properties.getString("myVar_preference"); '// returns "myValue"

Titanium build and iPhone simulator issues

I've found that the iPhne simulator and Titaniums build process are quite buggy. For instanace I have had numerous occasions where for no apparent reason Titanium refuses to launch in the simulator. Sometimes there is an error message -- like the iPhone SDK was installed in the wrong place -- and other times it launches and then just shuts down without an error code.

I've found that when there is no obvious reason for the issue, I create a new project and then copy all of the assets from the Resources folder of the original project and place them in the new project Resources folder and (usually) we're back in business.

It's a pain but after all it is free software! :-)

Saturday, September 25, 2010

Unable to write to filesystem using Titanium

This took several hours to figure out...

In Titanium Mobile it allows you to create and write to files in the Resources directory (Titanium.Filesystem.resourcesDirectory) using the emulator, but it fails when you try to run it on the iPhone. This is because you don't have actual write permissions on that directory -- you need to save data to the Titanium.Filesystem.applicationDataDirectory.

Here is how you write to a file: (btw -- if the file does not already exist, it creates it automatically -- you don't need to use the Ti.Filesystem.createFile() method)

var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'myFile.txt');
f.write('this is the new file');

To read the contents of a file:

var g = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'myFile.txt');
var contents = g.open();
Titanium.API.info("Contents of the file = " + contents.text);

Thursday, September 23, 2010

Window height in Titanium/iPhone

Just a caution: while using Appcelerator Titanium, we aware that Titanium.Platform.displayCaps.platformHeight includes the iPhone status bar height -- which is essentially unusable real estate since it always shows in an application. So you have to deduct 20 to get the actual usable space on an iPhone.

For instance:

I created a buttonbar (with a height of 50) and wanted position it at the bottom of the screen. So I thought that the easiest way would be to use the Titanium.Platform.displayCaps.platformHeight as my layout height and then just set the buttonbar to have a top value of Titanium.Platform.displayCaps.platformHeight - myButtonBar.height.

However, this always placed the buttonbar too low on the screen. It was only when I modified the variable to account for the 20 pixel status bar did everything line up properly:

Titanium.Platform.displayCaps.platformHeight - myButtonBar.height - 20

Wednesday, September 22, 2010

"Error creating project" in Titanium

I had installed Titanium a few months ago and had not used it for a while but when I tried to create a new project -- or compile an old one -- I kept getting errors.

In the end, I installed the Android SDKs and followed the advice in this post:

https://developer.appcelerator.com/question/34821/build-failed

but without installing the patch.

After this was all done -- and updated -- Titanium allowed me to correctly create a new project from iPhone but it still doesn't find the Android SDK. I'll leave that for another day....

Phonegap for iPhone development

For what it might be worth to others, I have tried Phonegap for a while now and although its relatively easy to get started if you have a straight forward html/javascript project, it doesn't seem to be so simple to access the native functions of the iPhone. For instance, I tried to implement the tab bar and after several tries found that it does not position properly -- nor could I quite figure out how to add an icon to a tab item.

I'm going to try and use Titanium and see how hard it is to port the existing code to it.

Tuesday, September 21, 2010

Firefox download manager

After failing for the second time to successfully download the newest XCode and iPhone SDK (3+Gb) I found this list of download managers on LifeHacker:

http://lifehacker.com/347827/top-10-free-download-managers

It seems the highest rated is the Firefox extension: Download Them All!

Update: Turns out that Apple has a non-resume on their SDK download so I had to try a few more times before I got the whole thing down in one try....

Monday, September 20, 2010

XCode shows: "No provisioned iPhone device is connected"

In case this is helpful for anyone else. I was trying to install a demo iPhone project on my iPod Touch and got the error: "No provisioned iPhone device is connected". I knew that I had the provisioning set up -- but it turns out that I had not upgraded the SDK -- so while the iPod Touch was 4.0, the SDK was 3.2. Once the SDK was updated the install went fine.

Friday, September 17, 2010

Solved - Problem connecting Mac using Check Point SecureClient

On a Mac (Snow Leopard) I was having issues using a Check Point Secure access. I kept getting "Gateway not responding | Connection failed". I had installed the latest software from Check Point (Check Point VPN-1 SecureClient NG with Application Intelligence - R56 HFA2 Build Number 015), but I was still having a problem.

A friend finally suggested that I try disabling NAT filtering in my modem.

This solved it!

Saturday, September 4, 2010

Restrictions on flash fullscreen mode

From Adobe:
  • The ActionScript that initiates full-screen mode can be called only in response to a mouse click or keypress. If it is called in other situations, it will be ignored (in ActionScript 2.0) or throw an exception (in ActionScript 3.0).
  • Users cannot enter text in text input fields while in full-screen mode. All keyboard input and key-related ActionScript is disabled while in full-screen mode, with the exception of the keyboard shortcuts that take the viewer out of full-screen mode.
That last bit is sad news if you want to allow a user to share via email while in fullscreen mode :-(