Sunday, April 11, 2010

Just to remember - size of iphone components

From idev101

Element Size (in pixels)
Window (including status bar) 320 x 480px
Status Bar
(How to hide the status bar) 20 px
View inside window
(visible status bar) 320 x 460
Navigation Bar 44 px
Nav Bar Image /
Toolbar Image up to 20 x 20 px (transparent PNG)
Tab Bar 49 px
Tab Bar Icon up to 30 x 30 px (transparent PNGs)
Text Field 31 px
Height of a view inside
a navigation bar 416 px
Height of a view inside
a tab bar 411 px
Height of a view inside
a navbar and a tab bar 367 px
Portrait Keyboard height 216 px
Landscape Keyboard height 140 px
Viewing / Adjusting Sizes in Interface Builder
Sizes for specific UI elements (buttons, text fields, images, etc.) can be adjusted in the size panel of the Inspector window (↑⌘I):
icon shortcut
⌘3 Size is the size and location (in X,Y coordinates) of the object on screen.

Size (and location) can also be adjusted programmatically:

[button setFrame:CGRectMake(x, y, width, height)];

The x, y position refers to the top left corner of the view being positioned.
Frame and Bounds

The frame is the outer container for the view - the position of the item within its enclosing superview. x is the distance left-right, where x = 0 is the left side. y is the distance up-down, where y = 0 is the top of the frame.

The bounds rectangle determines the origin and scale in the view's coordinate system within its frame rectangle. Setting this property changes the value of the frame property accordingly.

When you set the frame property, the size of the bounds property is set to match the size of the frame property. The center property is also adjusted to match the center point of the new frame.

Monday, January 4, 2010

Enable syslog in your iphone

I got into this when trying to understand how internally the iphone is enabling the location daemon
Source: Enable syslog on iphone

You can no longer debug output in 2.0 by launching your app from SSH. So how do you get those NSLog outputs? The answer is to enable the syslog and then you can use tail -f /var/log/syslog to see all the output. Here is how:

1. edit /System/Library/LaunchDaemons/
2. find the /usr/…/syslogd line
3. below that add:
4. Type: echo '*.* /var/log/syslog' > /etc/syslog.conf (open /etc/syslog.conf and make sure that you have *.* /var/log/syslog without any extra characters)
5. Type: launchctl unload /System/Library/LaunchDaemons/
6. Type: launchctl load /System/Library/LaunchDaemons/

And now you have an awesome /var/log/syslog that contains NSLogs (and I think stderr) from your application.

Remember, to see the output open SSH and type: tail -f /var/log/syslog to see all the output.

Source of these info: TheBigBoss website, and originally from Saurik.

Here’s an output example… frack!

Mar 23 09:56:37 iPhosk[198]: 259491397.100,static void CLFileUpdate::onDownloaded(CLFileDownload*, bool, void*): could not download from to /var/root/Library/Caches/locationd/clients-b.plist.temp

Sunday, October 11, 2009

Apple singleton implementation

This is Apple code recomendation for creating a singleton

static MyGizmoClass *sharedGizmoManager = nil;

+ (MyGizmoClass*)sharedManager{
@synchronized(self) {
if (sharedGizmoManager == nil) {
[[self alloc] init]; // assignment not done here
return sharedGizmoManager;

+ (id)allocWithZone:(NSZone *)zone{
@synchronized(self) {
if (sharedGizmoManager == nil) {
sharedGizmoManager = [super allocWithZone:zone];
return sharedGizmoManager; // assignment and return on first allocation
return nil; //on subsequent allocation attempts return nil

- (id)copyWithZone:(NSZone *)zone{
return self;

- (id)retain{
return self;

- (unsigned)retainCount{
return UINT_MAX; //denotes an object that cannot be released

- (void)release{
//do nothing

- (id)autorelease{
return self;

Monday, June 8, 2009

How to Get Rid of Security Policy Error

This week, after getting my new MBP, I was trying to deploy my new iPhone application to my testing device (iPhone 3G). After going through all code signing/provisioning issues I managed to deploy my app. However, when GDM tries to run it, I was getting an exception that says “Error from Debugger: Error launching remote program: Security policy Error“.

Security Policy Error

And it was unable to run my sweet app in my device. Everything was working perfectly in Simulator, but not in device. After a little googling, I found the solution. Before going into the tip, I want to let you all know guys, this problem only occurs if your iPhone is jailbroken.

Okayyy, here is the tip: Please just add following lines into your Info.plist file and save the world :)

Apple iPhone OS Application Signing

I hope it saves your day too :) Good luck!

CodeSign error: a valid provisioning profile is required

"CodeSign error: a valid provisioning profile is required for product type 'Application' in SDK 'Device - iPhone OS 2.2"

This error will appear when you update your provisioning profile in iPhone SDK 2.2
or after the expiration of developer certificate and that you have a new provisioning profile from the developer portal

This is the solution (which is modified from

Suppose you have copied your provisioning profile called "iPhone_Development.mobileprovision" to the Library folder and build & go an old iPhone project called "MyApp", and this annoying error appears

(1) cd ~/Library/MobileDevice/Provisioning\ Profiles/

(2) find out the UUID of the provisioning profile
strings iPhone_Development.mobileprovision | grep ".*-.*"

output is like this

(3) copy that UUID between the string tag

(4) close xcode and go to your project
cd ~/Projects/MyApp/MyApp.xcodeproj

(5) Use a text editor to open the project.pbxproj

paste the UUID that you copied from step (3) and put it in both Debug and Release Sections (do multiple finds) for the following line
PROVISIONING_PROFILE = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

(6) Launch XCode and open the project and build & go again

Wednesday, February 25, 2009

iPhone Database Details

A useful resource for the different databases in the iPhone
iPhone databases



key (TEXT)value (TEXT)




Auto-incrementing field/counter

address (TEXT)

International-formatted foreign address


date (INTEGER)

OSX-epoch based datetime, convertable via date -r


text (TEXT)

Content of text message

(This is the text message)

flags (INTEGER)

Flags controlling the type of record

2 - Message sent from address to iPhone

3 - Message sent from iPhone to address

129 - Message log erased from iPhone but addressee still in SMS index

replace (INTEGER)

Unknown, always 0 in my case

svc_center (TEXT)

service center, seems null in my case

CallData DB


code (INTEGER)

Not sure what the significance of these entries are, I’m wondering if they have something to do with the geocoding of calls not made from your phonebook?


city (TEXT)

Not sure what the significance of these entries are, I’m wondering if they have something to do with the geocoding of calls not made from your phonebook?


citycode (code)

npa (TEXT)

Numbering Plan Area, aka Area Code


location (TEXT)

State/Province Assigned to the NPA


country (TEXT)

Country Assigned to the NPA, may be null if “location” is specific enough


npa (TEXT)

Numbering Plan Area, aka Area Code


location (TEXT)

Descriptive location info

(San Francisco/North Bay Area)


Numbering Plan Area, aka Area Code





rate_center (INTEGER)



npanxx (npa,nxx)

CallHistory DB


your values will certainly be different here…when you “restore” your iPhone from iTunes the counters all reset

key (TEXT)value (TEXT)


















Auto-incrementing field/counter

address (TEXT)

International-formatted foreign address


date (INTEGER)

OSX-epoch based datetime, convertable via date -r


duration (INTEGER)

Length of call in seconds rounded to next minute, 0 = missed call


flags (INTEGER)

Flags controlling the type of record

5 - Outgoing call

4 - Incoming call


AddressBook ID for outgoing calls selected from AddressBook, otherwise -1


call (date)

KeyChain DB
Encrypted, I don’t know how to parse this yet

Notes DB


key (TEXT)value (TEXT)



creation_date (INTEGER)

title (TEXT)

summary (TEXT)



Voicemail DB


key (TEXT)value (TEXT)



tokenstring containing various values, including your phone number




Auto-incrementing field/counter

remote_uid (INTEGER)

International-formatted foreign address


date (INTEGER)

OSX-epoch based datetime, convertable via date -r


token (TEXT)

Always reads “Complete” from what I can tell

sender (TEXT)

CallerID from the calling party leaving the voicemail message


callback_num (TEXT)

Callback number left by calling party, usually caller ID


duration (INTEGER)

Duration in seconds


expiration (INTEGER)

OSX-epoch based datetime, convertable via date -r


trashed_date (INTEGER)

definitely based in seconds, haven’t figured out the epoch yet or why it isn’t the same as the other dates based on OSX’s epoch

flags (INTEGER)

Voicemail flags

0 - Not downloaded yet

1 - Partially downloaded

2 - New, unlistened or only partially listened to

3 - Listened completely

11 - Pending delete, in “Deleted Items”

15 - Deleted from iPhone, pending delete from voicemail hq

voicemail (date)

voicemail (remote_uid)

Other, more complicated DBs, involved in syncing
AddressBook DB
AddressBook Images DB
Maptiles DB
Calendar DB

Sunday, February 1, 2009

Tips for quick documentation

1. Hold "option" key down, cursor turns into PLUS, click on any function/method/arg etc.. to display xcode doc for that item.

2. Turn on research assistant to display window that presents docs, args etc.. for whatever item you select in the editor.

Another tip is to use Open This Quickly. This feature allows you to go directly to any header file or symbol name by typing its name and from there directly to the Xcode documentation for that symbol.

I have set command-D to Open This Quickly. The default is a little different and I prefer it this way.

Usual action is this

Cmd-D and the Open This Quickly window opens
Type a header file name or symbol name, say UILabel.h
Hit return and the header file opens

If I type a symbol name like say sizeWithFont it opens the header file that holds that symbol and selects it. I can then use option-double-click to open the Xcode docs for that symbol.

Also, if you put the insertion point in the name of a header file and then hit command-D the header file will open.