ios 7.1 flash 模式不工作

Posted

技术标签:

【中文标题】ios 7.1 flash 模式不工作【英文标题】:ios 7.1 flash mode don't work 【发布时间】:2014-04-18 14:27:55 【问题描述】:

这是我在 iphone 上更改闪光灯模式的代码。

ios7.0工作:flashmode(0,1,-1)

在 ios7.1 中不起作用:flashmode(0,0,0)

//UIImagePickerControllerCameraFlashModeOff  = -1,
//UIImagePickerControllerCameraFlashModeAuto = 0,
//UIImagePickerControllerCameraFlashModeOn   = 1

NSInteger flashMode = self.pickerReference.cameraFlashMode;

NSLog(@"flashmode %i",flashMode);

if (flashMode == UIImagePickerControllerCameraFlashModeAuto) 
    [(UIButton *)sender setImage:[UIImage imageNamed:@"flashYesComposeButton.png"] forState:UIControlStateNormal];
    self.pickerReference.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;


else if (flashMode == UIImagePickerControllerCameraFlashModeOn) 
    [(UIButton *)sender setImage:[UIImage imageNamed:@"flashNoComposeButton.png"] forState:UIControlStateNormal];
    self.pickerReference.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;


else if (flashMode == UIImagePickerControllerCameraFlashModeOff)

    [(UIButton *)sender setImage:[UIImage imageNamed:@"flashAutoComposeButton.png"] forState:UIControlStateNormal];
    self.pickerReference.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;

【问题讨论】:

***.com/questions/22457097/… 对我不起作用 【参考方案1】:

我之前遇到过这个错误

问题是,无论在ios 7.1 中真正的flash state 是什么,它总是返回UIImagePickerControllerCameraFlashModeAuto。有趣的是,如果你将闪光灯模式设置为UIImagePickerControllerCameraFlashModeOff,闪光灯确实会关闭,但如果你问状态,它仍然是UIImagePickerControllerCameraFlashModeAuto

所以我通过保留自己的“flashState”解决了我的问题。单击时,我手动更改了自己的状态,并且从不相信发回的状态,而是 UIImagePickerController。

@property (nonatomic) UIImagePickerControllerCameraFlashMode flashMode;

当按钮被点击时:

       if (self.flashMode == UIImagePickerControllerCameraFlashModeAuto)   
            //toggle your button to "on"
            self.flashMode = UIImagePickerControllerCameraFlashModeOn;
        else if (self.flashMode == UIImagePickerControllerCameraFlashModeOn)  
            //toggle your button to "Off"
            self.flashMode = UIImagePickerControllerCameraFlashModeOff;
        else if (self.flashMode == UIImagePickerControllerCameraFlashModeOff) 
            //toggle your button to "Auto"
            self.flashMode = UIImagePickerControllerCameraFlashModeAuto;
        

【讨论】:

以上是关于ios 7.1 flash 模式不工作的主要内容,如果未能解决你的问题,请参考以下文章

iOS 10:UIImagePickerViewController 无法设置 Flash 模式

iOS 6/7 Delta 不工作 iOS 7.1

反应本机应用程序在调试模式下工作,但在 ios 上不工作发布模式

Firebase 消息传递仅在调试模式下工作,而不是在发布模式下工作 (iOS)

ionic iOS FCM 在开发模式下工作,但在生产模式下不工作

7.1 vim编辑器