Apple Code Signing

I was just released from being mired in litany of predicaments due to code signing procedures and here's my story...

So I work on a new macbook, someone else's, and i fail to code sign my app before deploying it to my device.

After two days I finally figured it out. (or better put: people sharing their knowledge on internet got it figured out).

Basically, code signing process is following:

You need to have the following in your computer when code sign:
- public and private key pair.
- certificate issued by you (if you are administrator of your Apple developer program)
- Apple intermediate certificate.

You got to have public and private key for code signing. This pair is created on your computer when you created certificates and provisioning profile FOR THE FIRST TIME. If you move development to other machine, you will have to do something to move this pair to the new machine.... The easiest way would be to re-create everything from scratch: delete your certificate in developer.apple.com and recreate it by submitting new certificate request from keychain.

If you develop on a new machine, the private key is usually missing. You can tell by going to the keychain. Your certificate should have a little triangle next to it, that you can click and it will show you the public and private key pair. If you don't have that triangle, you have the certificate but not the key pair and your code signing won't work.

The intermediate certificate can be downloaded from the the usual place in developer site without having to submit certificate request first. If you don't install this, you'll get this error from XCode: /usr/bin/codesign fail or something similar.

Code signing is one part. Then there's this thing called provisioning profile which basically says which certificate to sign which app and which app can be deployed on which device...

Er... I'm unsure. But that's my impression of two days fixing code signing error.

One more thing, I deleted all passwords in keychain because I used my own apple credential in XCode automatic refresh and now I wanted to use someone else's. I couldn't find the right password for XCode in keychain so I deleted them all. .-))
It worked. I was asked to enter new credential when I clicked refresh in XCode organizer. But another problem arose: When I created certificate request it gave me errors like incorrect passphrase or something. I could not create certificate request because I deleted all of my passwords! Solution is simple: restart the computer!

InnoDB status, altering table by dropping foreign key column

So if you have a table, say Kinerja, that has a foreign key column, say NIP. And you need to alter that table by dropping the column, you can't just do:

alter table Kinerja drop column NIP;

It will spit errno 150 at ya.

You need to first drop the foreign key constraint pertinent to the said column, such as:

alter table Kinerja drop foreign key the_constraint_of_NIP_column_here;

After that is done, you can do:

alter table Kinerja drop column NIP;

But how to get the constraint? Well, just do:

alter table Kinerja drop column NIP;

first to get error. And then, look up the innoDB log by issuing:

show engine innoDB status;

In the log, find this paragraph:


------------------------
LATEST FOREIGN KEY ERROR
------------------------
121211  0:16:23 Error in foreign key constraint of table penilaian/kinerja:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
  CONSTRAINT "kinerja_ibfk_2" FOREIGN KEY ("NIP") REFERENCES "dosen" ("NIP")


There, you have the constraint! :p

Then, do delete the constraint and then the column.

Playing video with cocos2d


  1. Download cocos2d extension from: https://github.com/cocos2d/cocos2d-iphone-extensions
  2. Unzip, navigate into the directory: extensions -> CCVideoPlayer.
  3. Copy file CCVideoPlayer.h and CCVideoPlayer.m and the folder iOS. 
  4. Insert them anywhere in the project.
  5. In CCVideoPlayer.m, comment out the line #import "CCVideoPlayerImplMac.h"
  6. Done! To play video, simply do: [CCVideoPlayer playMovieWithFile:@"filename.mp4"]
  7. You can set a delegate to the CCVideoPlayer by implementing protocol: <CCVideoPlayerDelegate>
  8. The protocol will call method: 
    -(void) movieStartsPlaying
    when the movie starts
    and
    -(void) moviePlaybackFinished
    when the movie finishes.

Find the total force when two fixtures collide

contact->GetManifold().localPoint.Length()

Remove CCNode from parent after a sequence of actions

P.S:
Well, P here stands for Pre instead of Post, I guess. The following cocos2d discussion was started 3 years ago. Now I realize that there is a method: [CCNode removeFromParent]

So a useful post from cocos2d forum: http://www.cocos2d-iphone.org/forum/topic/981



I have some sprites and labels on the Layer. Before removing them they must do some actions (fade out for example). But after that I need to remove them from the layer with using [self removeChild:child cleanup:YES]. For that I create classes AutoCleaningSprite and AutoCleaningLabel which inherit Sprite and Label class and have new method:
- (void) removeFromParent{
CocosNode *parent=self.parent;
[parent removeChild:self cleanup:YES];
}
So for removing this objects after animation I used next actions:
[someAutoCleaningSprite runAction:
[Sequence actions:[FadeOut actionWithDuration:0.5],
[CallFunc actionWithTarget:someAutoCleaningSprite selector:@selector(removeFromParent)],nil]];
Is it correct method? Or may be there is something more simple way for removing CocosNode objects from the parent Object?
And I have another question - is it need to invoke [sprite release]; after [self removeChild:sprite cleanup:YES];?
Thanks..
Answer:


re:
(void) removeFromParent{
CocosNode *parent=self.parent;
[parent removeChild:self cleanup:YES];
}
This strategy will work and I've found it very useful on my projects but one thing anyone who tries it needs to be aware of is a really really really evil memory bug that gets caused unless your careful. First off, the solution:
CocosNode *parent=self.parent;
[self retain];
[parent removeChild:self cleanup:YES];
[self autorelease];
Huge hack I know, and there are cleaner ways to do this but what happens if you don't is total heisenbuggery. Background:
- The NSInvocation object associated with the CallFunc action wants to write a 'return value' to an address in the NSInvocation object ... even if your function doesn't return anything.
- When you call removeChild:self cleanup:YES your sprites ref count goes down by one
- If your sprites ref count just hit zero (as it probably will), instead of being released 'at some time in the future' its going to get deallocated NOW. Thank apple for that little bit of magic they do when removing objects from NSArrays
- That deallocation cascades to the Action and then the NSInvocation all before your function returns.
If you've got anything else going on (other threads for instance that may be allocating something ... I'm looking at you OpenFeint) the NSInvocation return is about to write on some memory that no longer belongs to it ... and you will likely not find out about it until way past too late ;)

Check whether a string contains substring.

Turns out that the Foundation Framework does not have this nifty little utility to check whether a string contains a substring. But this can be easily done manually:


-(BOOL)string:(NSString*)string1 containsString:(NSString*)string2{
    NSRange rangeValue = [string1 rangeOfString:string2 options:NSCaseInsensitiveSearch];
    if (rangeValue.length > 0){
        return TRUE;
    }
    else {
        return FALSE;
    }
}

Manual OpenGL draw on CCNode

Every point must be multiplied by     CC_CONTENT_SCALE_FACTOR();

Otherwise, the drawing will not be correctly placed on the screen!