Ad

Our DNA is written in Swift
Jump

Don't abuse standard buttons

Four days ago I had submitted a small app to the app store and yesterday I received feedback that I had to make some changes. Out of pure laziness I had re-purposed the “compose” button on a tool bar to call up a settings dialog.

“Applications must adhere to the iPhone Human Interface Guidelines as outlined in iPhone SDK Agreement section 3.3.5.

The compose button is to be used to open a new message view in edit mode. Implementing standard buttons to perform other tasks will lead to user confusion. We recommend using a custom icon.”

I must admit that Apple is right, we want to avoid user confusion at any cost. Also kudos to them for really being strict even if this means for us small-time developers that you have to submit your app with changes several times until they give it the nod.

I ended up creating my own button with a custom image of a cockwheel and while being at it I also replaced the play button with a record button, again by my own design.

Mysterious PLIST

I have grown very fond of using NSDictionary and NSMutableDictionary if I want to put diverse data into a single object to pass around in my programs. Also NSDictionary has the built-in capability of saving and reading itself to disk, in the so-called property list (abbreviated as “plist”) format.

Now I was implementing caching of such a NSDictionary in my app and for mysterious reasons the following code would not result in any file being saved:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"notworking.plist"];
 
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSNumber *numKey = [NSNumber numberWithInt:123];
[dict setObject:@"a Value" forKey:numKey];    // legal: using a NSNumber as key
 
[dict writeToFile:path atomically:YES];
[dict release];

Can you spot the problem? Probably not, if you check the documentation you will read that NSDictionary can hold and save any of the following data types: NSNumber, NSData, NSString, NSDictionary, NSArray. I did not use anything else, therefore the dictionary should be saved as a plist. With lots of experimenting however I found a simple change to the above code that makes it work:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"working.plist"];
 
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSString *stringKey = @"123";
[dict setObject:@"a Value" forKey:stringKey];    // workaround
 
[dict writeToFile:path atomically:YES];
[dict release];

Simply put you cannot use anything except as a string as the root key of an NSDictionary. The above code will save an XML file looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>123</key>
        <string>a Value</string>
</dict>
</plist>

If you want to save a dictionary, make sure you use only strings for keys. In another case I was using an NSDate as valid key for an entry in a dictionary. Same result: writing it to a file does not work. Why there is such a limitation I cannot say. In any case I submitted it as bug report to Apple.

Having pondered this a little I realized the most probable explanation. If you look at the way an XML plist is represented in the file you can see that there is no indication as to what data type the <key> represents. Therefore it can only be a string.

Showing Version Info

I found that I need some place to show a version in my apps, because otherwise I and my testers never know if we are talking about the same version. A problem they might be having could have already been fixed previously. Without a version info you are at a loss.

Here’s a version info box, that I came up with. This shows how to access the version string from Info.plist as well as open a new mail to the author.

- (IBAction) showAppInfo:(id)sender
{
	// a convenient method to get to the Info.plist in the app bundle
	NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
 
	// get two items from the dictionary
	NSString *version = [info objectForKey:@"CFBundleVersion"];
	NSString *title = [info objectForKey:@"CFBundleDisplayName"];
 
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[@"About " stringByAppendingString:title]
						  message:[NSString stringWithFormat:@"Version %@\n\n© 2009 Drobnik.com", version]
						  delegate:self
						  cancelButtonTitle:@"Dismiss"
						  otherButtonTitles:@"Contact", nil];
	[alert show];
	[alert release];
}
// this function from UIAlertViewDelegate is called when a button is pushed
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	UIApplication *myApp = [UIApplication sharedApplication];
 
	// cancel button has index 0
	switch (buttonIndex) {
		case 1:
		{
			[myApp openURL:[NSURL URLWithString:@"mailto:oliver@drobnik.com"]];
			break;
		}
		default:
			break;
	}
 
}

Two buttons are displayed side by side. Three or more are vertically stacked. This is how the result from the code about looks like:

All Purpose About Box

Call for Beta Testers – Mobile App Sales Report App

If you have a couple of apps where you get sales reports, haven’t you had the same problem as me, that daily reports are only available for 7 days and it’s a big hassle to keep downloading all of them. And even if you do, you don’t have any overview or analysis or charts…

ASiST First screenshot

Over the past two months I have been developing an App that runs on your iPhone and automatically downloads all new daily and weekly reports once you start the app. The reports are nicely shown with country flags and converted to your favorite currency. The report data is inserted into a local sqlite database which you can also transfer away from the iPhone via the built in web server. So the data is safe even long after Apple removed the report from the iTunes Connect site. There are also charts (1 so far, but more to come) to help you optically analyze sales trends and see how your apps are doing. The iTunes Connect logon is kept on the iphones secure keychain for safekeeping.

I am using it myself and every day I am anxious to see the previous day’s sales for my two apps and what the trend is.

I am looking for about a dozen people who would want to try out the app in different countries. Their benefit will be that they will get to keep the app for free and use forever.

A little more polishing and then I am going to find out wether Apple will permit such an app. Probably not, but if they do then it will be highly useful for everybody who is making the least bit of money in the store.

Future additions planned:

  • automatic downloading of customer feedback from iTunes
  • also downloading of financial reports
  • financial predictions of the current month’s approximate income
  • track when regions that are still below $250 will finally have earned enough to be cashed out
  • suggestions welcome

 To sign up for the BETA drop me an e-mail.

Remove Whitespace from NSString

In Cocoa Touch you always need to write more to achieve the same …

NSString *string = @" spaces in front and at the end ";
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
                                  [NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(trimmedString)

While such a standard task might look excessively much code to write, you gain many additional possibilites of what you could want to trim away. NSCharacterSet also knows these other sets. 

  • alphanumericCharacterSet
  • capitalizedLetterCharacterSet
  • controlCharacterSet
  • decimalDigitCharacterSet
  • decomposableCharacterSet
  • illegalCharacterSet
  • letterCharacterSet
  • lowercaseLetterCharacterSet
  • newlineCharacterSet
  • nonBaseCharacterSet
  • punctuationCharacterSet
  • symbolCharacterSet
  • uppercaseLetterCharacterSet
  • whitespaceAndNewlineCharacterSet
  • whitespaceCharacterSet

New Blog started

After blogging for 10 years in German I thought to myself, “Hey. This app development really starts being a serious part of my life. I’d better dedicate a dedicated blog to it!”

Every now and then I would blog programming related topics in a category on my personal blog, but those always felt somewhat misplaced. Then I am frequently discovering new ways how to manage certain tasks in Cocoa Touch, but didn’t have a place to put this new-found knowledge.

Now I do.

All the while I was blogging on my own blogging engine. But software development generally is a TEAM effort. In this case TEAM is a German acronym for  “Toll, ein anderer macht’s” which can be translated as “Great! Somebody else takes care of it!”

I want to concentrate on developing iPhone apps, not coding a blog engine. WordPress to the rescue! This blog was literally running within 5 minutes. And while I was at it, I remembered the suggestion of a BETA tester to find a place where people can submit bugs and suggestions for my apps. My future brother-in-law suggested Mantis and this was also running in only a few minutes. 

The bug reporting site for all my apps is now located at http://www.drobnik.com/bugs