Default.png
AKA "Splash screen", if you place a file named Default.png in the root of your application with
Build action: Content
then the iPhone will automatically display this while the application loads (rather than the "black screen").There's a few approaches you can take: the awesome Flight Control app uses a simple 'Please wait' banner (which conveniently prompts you to turn the phone sideways); my other sample uses a 'greyed out' copy of its UI with a 'loading...' message.
Alternatively you could take a screenshot before shut-down and save it as /Name.app/Default.png, so the next time it starts up it looks like you are continuing where you left off - even before the app is finished loading. UPDATE: here's some sample screenshot code to add to your
WillTerminate
methodInfo.plist
Whether you realise it or not, your MonoTouch app already contains an Info.plist file - right-click on your project →
Options
→ iPhone Application
→ Application Bundle
- these fields all end up in a MonoTouch-generated Info.plist. If you navigate with Finder to
/Projects/<your project>/bin/iPhone/debug/
and remove the .app
extension you can open your 'app' (it's just a folder!) then you can view the generated Info.plist that is sent to your device.That doesn't mean you are restricted from adding more details though! Remember that plist files are basically just a special 'Apple' form of XML. Simply add a text file to the root of your project and rename it Info.plist - MonoTouch will merge it with the
Options
before copying to the simulator/device. Here is a sample Info.plist (described below). DON'T FORGET to set the Build action:Content
in the file's properties.SBUsesNetwork & UIRequiresPersistentWiFi
Indicates to the operating system that your app uses connectivity. The Persistent setting keeps the WiFi running (so beware of running down the battery).
UIPrerenderedIcon
When
true
it tells the operating system that your icon is already pretty, and not to mess with it! When false
the icon is made shiny with curved corners for you. You probably want to leave it as the default: false!
UIStatusBarHidden
If true, totally HIDES the status bar (eg. for games such as Flight Control).
UIStatusBarStyle
Use this to turn the status bar from grey to black! The
UIPrerenderedIcon
example above also shows the UIStatusBarStyleOpaqueBlack
status bar style.UIInterfaceOrientation
If you change this from the default setting (eg. to
UIInterfaceOrientationLandscapeRight
) you should ensure you have provided landscape views in your application. You really don't want this effect:CFBundleURLTypes
If you read about initiating a call or other actions in MonoTouch you'll know about the use of
OpenURL
schemes to open other applications. Using
CFBundleURLTypes
in Info.plist informs the operating system of what schemes your application will respond to. If you use the sample Info.plist and view this blogpost on your iPhone, clicking initdial://123456789 will open your app! You probably also want to parse the parameters... but that's another post :)Custom schemes are really useful for social apps (eg. twitter clients, map stuff, etc). To learn more about what schemes are already available/used check out handleopenurl.com.
There are many more options you can set in Info.plist, and also other ways to control some of the things above (such as showing/hiding and changing the appearance of the status bar). Check out some of the Objective-C resources and try them for yourself!
I've created an Info.plist file with two entries, CFBundleIdentifier and UIStatusBarStyle, using your sample and placed it in the same folder as the .csproj file. MonoTouch does not merge it. So then I added it into the project. Still does not merge. I also tried putting into the folder that contains the solution file. What am I doing wrong?
ReplyDeleteIt needs to be in the 'root' of your solution, and you need to set the type to "Content" in File Properties. Also double check the filename is Info.plist (the Mac can sometimes hide the true extension).
ReplyDeleteHTH
Thanks. The problem was forgetting the Content type. I can see that the file is merged now. Simulator does not show the black status bar style, but I assume that's just the simulator.
ReplyDeleteI'm pretty sure Stanza does not modify Default.png - short of an unapprovable symlink hack around, you can't do that. Their Default.png is black. Once the app launches they show a greyed page while they fetch the ebook contents.
ReplyDeleteHey Hafthor, I think you're right about Stanza - it just seems to start up very quickly.
ReplyDeleteHowever as for replacing Default.png, I tried this out in another post and it seems to let me save a new Default.png in the application folder (eg. saving the img.AsPNG() NSData to "../iSOFlair.app/Default.png").
I thought this would be particularly useful for MonoTouch apps since they seem to start a little slower (due to the 'Framework' loading??)
Hey Hafthor - I take that back - my code seems to work fine on the Simulator but doesn't seem to work on the device :-(
ReplyDeleteI'm not very far along in the app dev process yet: I've only used the simulator so far. Care to make a guess as to how much faster startup is in the simulator (2.1GHz MacBook) than the device?
ReplyDeleteOn the simulator, my Default.png only shows for a split second before being replaced by the app's UI.
Impossible to guess - but all the doco warns not to assume the timings in the Simulator will be the same on actual devices. Also remember there are different device capabilities (the 3GS has a faster processor than the older iPhones, for example).
ReplyDeleteWith MonoDevelop 2.2 beta 2 (2.1.1) I had to do this differently. Add a new file and pick "iPhone Application Manifest Template".
ReplyDeleteIt will add an info.plist file to your project, and launch the property editor. Add your properties as you see fit, and then that's it. Don't set it to build action content. This way MD merges the keys with the ones it creates. If you set it to build action content, it instead makes the plist you just created be the only plist for the app.
To get around the 'Default.png only shows for a split second' issue add the following code to Main.cs:
ReplyDeleteUsing System.Threading
...
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Thread.Sleep(3000);
...
}
Note that this will display the splash screen for 3 seconds.