Menu Home

ios

NSNotification的同步运行

Same Thread – (void)viewDidLoad { [super viewDidLoad]; NSLog(@”viewWillAppear”); [[NSNotificationCenter defaultCenter] addObserverForName:@”Test_NOTIFY” object:self queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) { NSLog(@”In Observer: Thread = %@”, [NSThread currentThread]); [NSThread sleepForTimeInterval:5]; }]; [[NSNotificationCenter defaultCenter] postNotificationName:@”Test_NOTIFY” object:self]; NSLog(@”viewDidLoad Finished”); } Different Thread – (void)viewDidLoad { [super viewDidLoad]; NSLog(@”viewWillAppear”); [[NSNotificationCenter defaultCenter] addObserverForName:@”Test_NOTIFY” object:self queue:[NSOperationQueue mainQueue] […]

iOS: Audio Recorder

设置文件路径 – (NSURL *)soundFileURL { NSArray *dirPaths; NSString *docsDir; dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@”record.m4a”]; return [NSURL fileURLWithPath:soundFilePath]; } 录音部分 – (IBAction)startRecording:(UIButton *)sender { [self.recordButton setHidden:YES]; [self.stopButton setHidden:NO]; [self.playButton setHidden:YES]; NSError *error = nil; AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryRecord error:nil]; […]

iOS: bitcode

什么是bitcode Bitcode is an intermediate representationof a compiled program. Apps you upload to iTunes Connect that contain bitcodewill be compiled and linked on the App Store. Including bitcode will allowApple to re-optimize your app binary in the future without the need to submit anew version of your app to the […]

iOS: create thumbnail by means of offscreen image context

– (void)setThumbnailFromImage:(UIImage *)image { CGSize origImageSize = image.size; CGRect newRect = CGRectMake(0, 0, 40, 40); float ratio = MAX(newRect.size.width / origImageSize.width, newRect.size.height / origImageSize.height); UIGraphicsBeginImageContextWithOptions(newRect.size, NO, ratio); UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:5.0]; [path addClip]; CGRect thumbRect; thumbRect.size.width = ratio * origImageSize.width; thumbRect.size.height = ratio * origImageSize.height; thumbRect.origin.x = (newRect.size.width […]

iOS:UIImagePickerController限制选择视频文件

#import <MobileCoreServices/MobileCoreServices.h> UIImagePickerController *videoCapture = [[UIImagePickerController alloc] init]; NSArray *availableTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; if ([availableTypes containsObject:(__bridge NSString *)kUTTypeMovie]) { [videoCapture setMediaTypes:@[(__bridge NSString *)kUTTypeMovie)]]; }

iOS: Capture Video use Camera

– (void)takeVideo { UIImagePickerController *camera = [[UIImagePickerController alloc] init]; NSArray *availableTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; camera.mediaTypes = availableTypes; camera.sourceType = UIImagePickerControllerSourceTypeCamera; camera.delegate = self; } – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { //UIImage *image = info[UIImagePickerControllerOriginalImage]; // 不同于获取图片,我们从Delegate中取得的是所拍摄视频的URL NSURL *videoURL = info[UIImagePickerControllerReferenceURL]; //拷贝所拍视频到用户相册中,并且删除临时目录中的视频文件 if (videoURL) { if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([videoURL path])) { UISaveVideoAtPathToSavedPhotosAlbum([videoURL path], […]