How to retrieve the most recent photo from Camera Roll on iOS?

One way is to use AssetsLibrary and use n – 1 as the index for enumeration. ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (nil != group) { // be sure to filter the group so you only get photos [group setAssetsFilter:[ALAssetsFilter allPhotos]]; if (group.numberOfAssets > 0) { [group … Read more

How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?

The short answer is that you’re using UINavigationController, and that won’t work like you want it to. From Apple’s docs: Why won’t my UIViewController rotate with the device? All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set. To make sure that all your child view controllers rotate … Read more

How to get the width of an NSString?

Here’s a relatively simple approach. Just create an NSAttributedString with the appropriate font and ask for its size: – (CGFloat)widthOfString:(NSString *)string withFont:(NSFont *)font { NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]; return [[[NSAttributedString alloc] initWithString:string attributes:attributes] size].width; }

Give warning when [super method] is not called

Recent versions of llvm have added an attribute that indicates that subclasses must call super: @interface Barn:NSObject – (void)openDoor NS_REQUIRES_SUPER; @end @implementation Barn – (void) openDoor { ; } @end @interface HorseBarn:Barn @end @implementation HorseBarn – (void) openDoor { ; } @end Compiling the above produces the warning: Method possibly missing a [super openDoor] call

How does Apple update the Airport menu while it is open? (How to change NSMenu when it is already open)

Menu mouse tracking is done in a special run loop mode (NSEventTrackingRunLoopMode). In order to modify the menu, you need to dispatch a message so that it will be processed in the event tracking mode. The easiest way to do this is to use this method of NSRunLoop: [[NSRunLoop currentRunLoop] performSelector:@selector(updateTheMenu:) target:self argument:yourMenu order:0 modes:[NSArray … Read more

Objective C: Send email without leaving app

Yes. Use the MFMailComposeViewController. // From within your active view controller if([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init]; mailCont.mailComposeDelegate = self; [mailCont setSubject:@”yo!”]; [mailCont setToRecipients:[NSArray arrayWithObject:@”[email protected]”]]; [mailCont setMessageBody:@”Don’t ever want to give you up” isHTML:NO]; [self presentViewController:mailCont animated:YES completion:nil]; } // Then implement the delegate method – (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [self dismissViewControllerAnimated:YES … Read more