Nov 18, 2014 - NSURLSessionDownloadTask save custome file path

1) サンプルソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- (void)downloadFile: (NSURL *)url filePath: (NSString *)filePath process:(void(^)(bool success)) process
{
    if (![FileUtils fileExists:filePath]) {
        [FileUtils mkdirIfNotEist:filePath];
    }
    
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
        NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:filePath isDirectory:YES];
        return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
    } completionHandler:^(NSURLResponse *response, NSURL *filePathTmp, NSError *error) {
        process(YES);
    }];
    
    [downloadTask resume];
}

documentsDirectoryURLはcustom file pathです。

Nov 18, 2014 - ios imageview corner radius

1) 在使用的文件中引入下面的文件

1
 #import <QuartzCore/QuartzCore.h>

2)追加设定的代码

imageView是UIImageView类型

1
2
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;

Nov 18, 2014 - FMDB query or update, get error message

直接看下面的例子,就会明白

1
2
3
4
5
6
BOOL ab = [db executeUpdateWithFormat:@"insert into users(name) values(%@)", @"test"];
if (ab) {
    
}else{
    NSLog(@"#########insert error message:%@", [db lastErrorMessage]);
}

主要是追加了 [db lastErrorMessage]