Tuesday, November 23, 2010

iPhone dev Stupidity 135: Codesign error

Codesign error: Provisioning profile cannot be found after deleting expired profile

Sometimes your xcode project file gets messed up, especially if you have an old project and first created it with an older version of xcode/iphone sdk. What you need to do is open up the project file in a text editor, search from the long sting and manually erase that line. In fact, you should just go aead and erase any line that points to any provisioning profiles. Then reopen the project in xcode, go to the settings are reselect your new profile. This clears up issues like that most of the time The lines that point to the provisioning profiles will look like this:


PROVISIONING_PROFILE = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";

iPhone dev Stupidity 134: Core Animation doc reading

* CALayer must be hosted with UIView. UIView provides the event-handling for underlying layers, while the layers provide display of the content.
  - for iPhone UIView.layer
  - for Mac OS, you need to enable it: theView.wantsLayer = YES

* Sublayers do not clip to parent by default (UIView does). To enable, theLayer.masksToBounds = YES

* To position content image in a CALayer:
  - kCAGravityResize
  - kCAGravityResizeAspect
  - kCAGravityResizeAspectFill

  will do a much better job than write your own resize & fill code

* You can stop an animation by: removeAnimationForKey:

* AffineTransform类描述了一种二维仿射变换的功能,它是一种二维坐标到二维坐标之间的线性变换,保持二维图形的“平直性”(译注: straightness,即变换后直线还是直线不会打弯,圆弧还是圆弧)和“平行性”(译注:parallelness,其实是指保二维图形间的相对位置关系不变,平行线还是平行线,相交直线的交角不变。)。仿射变换可以通过一系列的原子变换的复合来实现,包括:平移(Translation)、缩放(Scale)、翻转(Flip)、旋转(Rotation)和错切(Shear)。

* When an instance of CAAnimation receives the runActionForKey:object:arguments: message it responds by adding itself to the layer’s animations, causing the animation to run:

- (void)runActionForKey:(NSString *)key 

                 object:(id)anObject 

              arguments:(NSDictionary *)dict 

{ 

     [(CALayer *)anObject addAnimation:self forKey:key]; 

} 




iPhone dev Stupidity 133: switch action for button

UIControl's addTarget:action:forControlEvent: method will allow multiple listeners be added.

If you just care about one listener and want to switch to another action, check this:

@implementation UIButton (Ext)


- (void) switchToAction: (SEL) newSelector forControlEvents: (UIControlEvents) event{

// get the old target/action pair

NSSet * targets = [self allTargets];

assert(targets.count == 1);

id target = [targets anyObject];

NSArray * action_strs = [self actionsForTarget: target forControlEvent: event];

assert(action_strs.count == 1);

NSString * action_name = [action_strs objectAtIndex: 0];

SEL action = NSSelectorFromString(action_name);

// remove it

[self removeTarget: target action: action forControlEvents: event];

// set new selector

[self addTarget: target action: newSelector forControlEvents: event];

}


@end



iPhone dev Stupidity 132: Sending picture attachment via email

using MFMailComposeViewController:

// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];

Yes. You can attache multiple images.

iPhone dev Stupidity 131: Quartz 2d coords

from Apple Doc:

Because you use a lower-left origin when drawing into a bitmap or PDF context, you must compensate for that coordinate system when rendering the resulting content into a view. In other words, if you create an image and draw it using the CGContextDrawImage function, the image will appear upside down by default. To correct for this, you must invert the y-axis of the CTM (by multiplying it by -1) and shift the origin from the lower-left corner to the top-right corner of the view.

If you use a UIImage object to wrap a CGImageRef you create, you do not need to modify the CTM. The UIImage object automatically compensates for the inverted coordinate system of the CGImageRef type.