iPhone OS – Don’t use dateWithCalendarFormat:timeZone

12/02/2010

My January iPhone Project was recently ‘not allowed’ onto the app store for a very simple reason:

“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.”

The non-public API that is included in your application is: dateWithCalendarFormat:timeZone:.


If you have defined a method in your source code with the same name as the above mentioned API, we suggest altering your method name so that it no longer collides with Apple’s private API to avoid your application being flagged with future submissions.


dateWithCalendarFormat:timezone: is an API I picked up either from a tutorial, or searching google, it is actually an old deprecated Cocoa API call, that works perfectly on the iPhone.

The Solution

More important is the solution. Luckily in this case the solution was straight forward.

Lets first have a look at the offending code:
//below dateWithCalendarFormat is not in iPhone use NSDateFormatter
//Sets a date string well (Incorrect….Apple Says Bad)
NSString *caldate = [[[picker date] dateWithCalendarFormat:@”%B %d, %Y”timeZone:nil] description];
NSLog(@”dateWithCalendarFormat (Apple Says Bad): %@”,caldate);

What to do:
//Trying new solution
NSDateFormatter *formatter = [[[NSDateFormatteralloc] init] autorelease];
[formatter setDateFormat:@"MMMM d, yyyy"];
NSString *caldate2 = [formatter stringFromDate:[picker date]]; 
NSLog(@”NSDateFormatter (Apple Says Good): %@”,caldate2);

Bring on the next API…

View Comments

  1. 19/03/2010taxpon.com | iPhoneではdateWithCalendarFormat:timeZone:が使えないお話 say:

    [...] iPhone OS – Don’t use dateWithCalendarFormat:timeZone 川の流れに月の影 iPhone NSDateFormatter [...]

Write a comment:

blog comments powered by Disqus