小编Joh*_*ohn的帖子

打开iPhone上的手电筒/闪光灯

我知道打开闪光灯并在iPhone 4上保持打开的唯一方法是打开摄像机.我不太确定代码.这是我正在尝试的:

-(IBAction)turnTorchOn {
    AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
    AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error = nil;
    AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];

    if (videoInput) {
        [captureSession addInput:videoInput];

        AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
        [videoOutput setSampleBufferDelegate:self queue:dispatch_get_current_queue()];

        [captureSession addOutput:videoOutput];

        [captureSession startRunning];

        videoCaptureDevice.torchMode = AVCaptureTorchModeOn;
    }   
}
Run Code Online (Sandbox Code Playgroud)

有人知道这是否有效还是我错过了什么?(我还没有iPhone 4进行测试 - 只是尝试了一些新的API).

谢谢

iphone ios avcapturesession avcapturedevice

45
推荐指数
4
解决办法
12万
查看次数

在CoreData中保存对象

我正在使用CoreData和iPhone SDK.我正在制作笔记应用程序.我有一个表格,上面有我的模型显示的注释对象.按下按钮时,我想将textview中的文本保存到正在编辑的对象中.我该怎么做呢?我一直在尝试几件事,但似乎都没有效果.

谢谢

编辑:

NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:detailViewController.textView.text forKey:@"noteText"];

NSError *error;
if (![context save:&error]) {
    /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, …
Run Code Online (Sandbox Code Playgroud)

iphone core-data

7
推荐指数
1
解决办法
3万
查看次数

Plist不会复制到文档目录

我在xcode的资源组中有一个plist文件.我想在app启动时将其复制到我的文档目录中.我使用以下代码(取自sqlite教程):

BOOL success;
NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"ActiveFeedsPlist.plist"];

success = [fileManager fileExistsAtPath:filePath];
if (success) return;

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"ActiveFeedsPlist.plist"];
success = [fileManager copyItemAtPath:path toPath:filePath error:&error];

if (!success) {
    NSAssert1(0, @"Failed to copy Plist. Error %@", [error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)

我收到错误"***终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:'无法复制Plist.错误操作无法完成.但是在控制台中没有这样的文件或目录'".

知道什么是错的吗?

谢谢

iphone nsfilemanager

4
推荐指数
1
解决办法
3363
查看次数