在我的項目,我需要自動拍照每隔一分鐘。但我找不到任何解決方案。如何在不按下圖像選擇控制器上的攝影按鈕的情況下自動拍照?
這是我實現的代碼,但它不工作...
我使用的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