iOS Notes

This blog is to record useful codes for iOS development.

Capture current screen

-(UIImage *)captureView:(UIView *)aView {
CGRect screenRect = [aView bounds];
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//CGContextFillRect(ctx, screenRect);
[aView.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
return newImage;

Share Framework

 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
    SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
    NSString *text = NSLocalizedString(@"trend", "");
    [mySLComposerSheet setInitialText:text];
    [mySLComposerSheet addImage:[self captureView:self.view]];
    [mySLComposerSheet addURL:[NSURL URLWithString:@""]];
    [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
        switch (result) {
            case SLComposeViewControllerResultCancelled:
                DLog(@"Post Canceled");
            case SLComposeViewControllerResultDone:
                DLog(@"Post Sucessful");

    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
} else {
    [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"socialSetting", nil)];

Resources folder in xcode

[NSBundle mainBundle] uses the “Resources” folder in a xcode project. This folder can be created by creating a “New Group”.

Retset Xcode’s preferences

run this command in Therminal

defaults delete

Look for simulator folder

Use SimPholders2

Browser simulator app Sqlite data

When using SqliteBrowser to browser data, dbname.sqlite, dbname.sqlite-wal and dbname.sqlite-shm must exit together. Otherwise the data of simulator database cannot be found.