在我的项目,我需要自动拍照每隔一分钟。但我找不到任何解决方案。如何在不按下图像选择控制器上的摄影按钮的情况下自动拍照?
这是我实现的代码,但它不工作...
我使用的NSTimer调出摄像头拍照,每4秒。而我只需要takepic
//This method is all for the time setup. You can ignore it.
-(NSDate *)userInfo {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm:ss"];
NSDate *date = [[[NSDate alloc]init]autorelease];
NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSLog(@"formattedDateString: %@", formattedDateString);
return date;
}
- (void)targetMethod:(NSTimer *)theTimer {
NSDate *startDate = [self userInfo];
//newly changed lines.
UIImagePickerController *myPicker;
[myPicker takePicture];
NSLog(@"Timer started on %@", startDate);
}
- (IBAction) showCameraUI {
[NSTimer scheduledTimerWithTimeInterval:4.0
target:self
selector: @selector(targetMethod:)
userInfo:[self userInfo]
repeats:YES];
}
感谢这么多的帮助。但我无法让它成功运行。你能读我的台词并给我一些建议吗?我是新的客观-c,所以... – 2012-02-21 12:00:13
你能描述你现在有什么行为吗?是否执行了'targetMethod:'?你确定执行targetMethod时'picker'不是'nil'吗? – sch 2012-02-21 12:22:47
我相信targetMethod:能够运行,因为如果我实现了的UIImagePickerController来看,它可以定期出来。但是,如果我只实现 – 2012-02-21 15:19:37