Friday, December 09, 2011

Wrong info from proc_pidinfo

proc_pidinfo is a very useful function to get a Mac OS X process's info such as the size of resident memory, consumed CPU time.

However, sometimes, the returned info is not correct. For example, a little process's resident memory becomes 4GB. Apple does not provide any document about this function, and I did not see useful comments in the header files.

I am lucky enough to see code snippet in the Apple open source file: http://www.opensource.apple.com/source/lsof/lsof-28/lsof/dialects/darwin/libproc/dproc.c. When we call proc_pidinfo, we must check the returned value. If the returned value is not identical to the size of output data, the output data is wrong.

      nb = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &ti, sizeof(ti));
            if (nb <= 0) {
                if (errno == ESRCH)
                    continue;
                if (!Fwarn) {
                    (void) fprintf(stderr, "%s: PID %d information error: %s\n",
                        Pn, pid, strerror(errno));
                }
                continue;
            } else if (nb < sizeof(ti)) {
                (void) fprintf(stderr,
                    "%s: PID %d: proc_pidinfo(PROC_PIDTASKALLINFO);\n",
                    Pn, pid);
                (void) fprintf(stderr,
                    "      too few bytes; expected %ld, got %d\n",
                    sizeof(ti), nb);
                Exit(1);
            }
I checked the processes with correct info. They are all my processes (not system processes). Seems like my app runs in user mode and it does not have privileges to get info of system processes.

Tuesday, October 18, 2011

Let Several Apps Use the same Facebook App ID

If you want to let your user post something from your app onto Facebook, you need to register a Facebook app and call Facebook SDK to post messages. But if you have a free version and a paid version, you would like to share the same Facebook App ID.

Just follow Facebook tutorial to register Facebook App and config your apps. https://developers.facebook.com/docs/mobile/ios/build/

The only one thing I need to mention is you must leave 'iOS Bundle ID' empty.

From Facebook doc page:

iOS Bundle ID - (Optional) You may set this to match the bundle ID for your iOS app. If you add this setting then the bundle ID of your app will be checked before authorizing the user. The benefit of this setting for SSO is if the user has already authorized your app they will not be asked to authorize it when they access your app from a new device.

Sunday, October 09, 2011

Xcode 4 and Git

I am new to Git. I used Perforce (P4) before, so I thought it is easy to use Git. Actually I was wrong. Git is not complex, but it has different concept.

In P4, we just check out and check in files. In Git, checking in has a new name Commit. When I committed my first change, I was surprised to see it does not appear in the server. Actually, Git did not really submit my code to the server. It was stored locally. I have to run this command in the command line:

git push origin master

So you must Push the local Commits to the server.

The problem is Xcode 4 can Pull, Commit, Compare, but does not provide Push functionality. How stupid the designer is. You can modify but cannot submit! Actually Pull, Commit and Compare are the only functionalities Xcode 4 provides. You cannot even revert!

Xcode 4 is free, but Apple should not make it suck.

Update on Nov 30, 2011:

SourceTree on Mac App Store is an excellent Git client. It is much better than GitX. And it is FREE!

Tuesday, October 04, 2011

Fixing the Problem of Cocos2D Game Disappearing in iPhone Simulator

I Created a new Cocos2D game. But it did not work well in iPhone simulator. It often disappeared in the simulator. I had to relaunch the simulator or relaunch Xcode. It was very boring. I didn't know why, because this project was still very simple.

I noticed there is a warning that Info.plist is included in the target. I did the following things:

1. Renamed Info.plist to ProjectName-Info.plist

2. Changed Info.plist to the same name in the target settings

3. Removed ProjectName-Info.plist from the target

The problem fixed!

Thursday, September 29, 2011

Why Use Cocos2D Instead of UIKit to Develop Games

I am leaning Cocos2D for iPhone. I am thinking why we should use cocos2D instead of UIKit to develop games.

Here are the reasons:

1. Cocos2D is built on OpenGL. You may not know OpenGL.

2. Cocos2D supports tiled map.

3. Cocos2D helps you reduce memory cost by supporting atlas images and providing CCSpriteBatchNode.

4. Cocos2D supports parallax backgrounds.

5. Cocos2D has more animations and transitions.

6. Cocos2D supports particle systems.

Cocos2D provides physics engines, but I don't think it is one of the reasons we should use Cocos2D. Because these physics engines are not designed for Cocos2D only. If you use UIKit, you can use these physics engines too.

Friday, August 19, 2011

Add Tool Tip to Controls with Xcode4

Like many Apple developers, I was a developer on Windows platform before. It is very easy to add tool tip to a control (e.g. a button) in Visual Studio. But I don't know how to do it in Xcode. When I am working on iPhone apps, it is not a problem because iPhone apps need not tool tip. But it is a problem when I am working on Mac apps.

Actually it is easy to add tool tip in Xcode 4. Looks like Apple put it in a wrong place. You need to add tool tip in Identity Inspector.

Add ToolTip in Xcode