• ios10 相机等权限

    2016-09-19 15:19:56
    ios10 相机等权限ios10新增的需要注册的权限在ios10升级之后 需要对这些权限进行手动注册

    ios10 相机等权限

    ios10新增的需要注册的权限

    在ios10升级之后 需要对这些权限进行手动注册

    这里写图片描述

    展开全文
  • ios 相机界面强制横屏

    2015-03-17 15:35:43
    IOS调用系统的相机默认是竖屏的,网上找了很多方法强制横屏都无效,以下代码经测试兼容ios78 自定义一个UIImagePickerController并且覆盖以下方法: -(UIInterfaceOrientation)...

    IOS调用系统的相机默认是竖屏的,网上找了很多方法强制横屏都无效,以下代码经测试兼容ios78

    自定义一个UIImagePickerController并且覆盖以下方法:

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

        return UIInterfaceOrientationLandscapeLeft;

    }


    - (NSUInteger)supportedInterfaceOrientations{

        return UIInterfaceOrientationMaskLandscape;

    }


    - (BOOL)shouldAutorotate {

        return YES;

    }


    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

        if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {

            return YES;

        } else {

            return NO;

        }

    }

    要兼容ios8还需要在delegate中加入以下代码

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

    {

        NSString* strSubClass = [NSString stringWithUTF8String:object_getClassName(window.rootViewController.presentedViewController)];

        if ([@"ImgTakeViewController" isEqualToString:strSubClass]) {

            return UIInterfaceOrientationMaskAll;

        }

        return [application supportedInterfaceOrientationsForWindow:window];

    }


    展开全文
  • iOS 获取照相机实时预览

    使用Objective-C实现
    AVController.h头文件

    #import <UIKit/UIKit.h>
    #import <AVFoundation/AVFoundation.h>
    #import <CoreGraphics/CoreGraphics.h>
    #import <CoreVideo/CoreVideo.h>
    #import <CoreMedia/CoreMedia.h>
    
    @interface AVController : UIViewController<AVCaptureVideoDataOutputSampleBufferDelegate> {
      AVCaptureSession *_captureSession;
      UIImageView *_imageView;
      CALayer *_customLayer;
      AVCaptureVideoPreviewLayer *_prevLayer;
    }
    
    @property (nonatomic, retain) AVCaptureSession *captureSession;
    @property (nonatomic, retain) UIImageView *imageView;
    @property (nonatomic, retain) CALayer *customLayer;
    @property (nonatomic, retain) AVCaptureVideoPreviewLayer *prevLayer;
    
    @end

    AVController.m实现

    @implementation AVController
    
    //@synthesize captureSession = _captureSession;
    //@synthesize imageView = _imageView;
    //@synthesize customLayer = _customLayer;
    //@synthesize prevLayer = _prevLayer;
    
    - (void)viewDidLoad
    {
      [super viewDidLoad];
      [self initCapture];
    }
    
    /**
     * 初始化摄像头
     */
    - (void)initCapture {
      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
      AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:device  error:nil];
      AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc]
                                                 init];
      captureOutput.alwaysDiscardsLateVideoFrames = YES;
      // captureOutput.minFrameDuration = CMTimeMake(1, 10);
    
      dispatch_queue_t queue = dispatch_queue_create("cameraQueue", NULL);
      [captureOutput setSampleBufferDelegate:self queue:queue];
      NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
      NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
      NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
      [captureOutput setVideoSettings:videoSettings];
      self.captureSession = [[AVCaptureSession alloc] init];
      [self.captureSession addInput:captureInput];
      [self.captureSession addOutput:captureOutput];
      [self.captureSession startRunning];
    
      self.customLayer = [CALayer layer];
      CGRect frame = self.view.bounds;
      frame.origin.y = 64;
      frame.size.height = frame.size.height - 64;
    
      self.customLayer.frame = frame;
      self.customLayer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI/2.0f, 0, 0, 1);
      self.customLayer.contentsGravity = kCAGravityResizeAspectFill;
      [self.view.layer addSublayer:self.customLayer];
    
      self.imageView = [[UIImageView alloc] init];
      self.imageView.frame = CGRectMake(0, 64, 100, 100);
      [self.view addSubview:self.imageView];
      self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
      self.prevLayer.frame = CGRectMake(100, 64, 100, 100);
      self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
      [self.view.layer addSublayer: self.prevLayer];
    
      UIButton *back = [[UIButton alloc]init];
      [back setTitle:@"Back" forState:UIControlStateNormal];
      [back setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
      [back sizeToFit];
      frame = back.frame;
      frame.origin.y = 25;
      back.frame = frame;
      [self.view addSubview:back];
      [back addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    -(void)back:(id)sender{
      [self dismissViewControllerAnimated:true completion:nil];
    }
    
    - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
           fromConnection:(AVCaptureConnection *)connection
    {
      CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
      CVPixelBufferLockBaseAddress(imageBuffer,0);
      uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
      size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
      size_t width = CVPixelBufferGetWidth(imageBuffer);
      size_t height = CVPixelBufferGetHeight(imageBuffer);
    
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
      CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace,                                                  kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
    
      CGImageRef newImage = CGBitmapContextCreateImage(newContext);
    
      CGContextRelease(newContext);
      CGColorSpaceRelease(colorSpace);
    
      id object = (__bridge id)newImage;
      // http://www.cnblogs.com/zzltjnh/p/3885012.html
      [self.customLayer performSelectorOnMainThread:@selector(setContents:) withObject: object waitUntilDone:YES];
    
      UIImage *image= [UIImage imageWithCGImage:newImage scale:1.0 orientation:UIImageOrientationRight];
      // release
      CGImageRelease(newImage);
    
      [self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
    
      CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
    }
    
    - (void)viewDidUnload {
      [self.captureSession stopRunning];
      self.imageView = nil;
      self.customLayer = nil;
      self.prevLayer = nil;
    }
    
    - (void) dealloc {
    //  [self.captureSession release];
    }
    
    @end

    使用Swift实现

    import UIKit
    
    class MyAVController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
    
      var captureSession:AVCaptureSession!
    
      var customLayer:CALayer!
    
      var imageView:UIImageView!
    
      var previewLayer:AVCaptureVideoPreviewLayer!
    
      override func viewDidLoad() {
        let device = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
        let captureInput = try? AVCaptureDeviceInput(device: device[0] as! AVCaptureDevice)
    
        let captureOutput = AVCaptureVideoDataOutput()
        captureOutput.alwaysDiscardsLateVideoFrames = true
    
        let queue = dispatch_queue_create("cameraQueue", nil)
        captureOutput.setSampleBufferDelegate(self, queue: queue)
    
        let key = kCVPixelBufferPixelFormatTypeKey as NSString
        let value = NSNumber(unsignedInt: kCVPixelFormatType_32BGRA)
        let videoSettings = [key: value]
        captureOutput.videoSettings = videoSettings
    
        captureSession = AVCaptureSession()
        captureSession.addInput(captureInput)
        captureSession.addOutput(captureOutput)
        captureSession.startRunning()
    
        customLayer = CALayer()
        var frame = self.view.bounds
        frame.origin.y = 64
        frame.size.height = frame.size.height - 64
        customLayer.frame = frame
        customLayer.transform = CATransform3DRotate(CATransform3DIdentity, CGFloat(M_PI) / 2.0, 0, 0, 1)
        customLayer.contentsGravity = kCAGravityResizeAspectFill
        self.view.layer.addSublayer(customLayer)
    
        imageView = UIImageView()
        imageView.frame = CGRectMake(0, 64, 100, 100)
        self.view.addSubview(imageView)
    
        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
        previewLayer.frame = CGRectMake(100, 64, 100, 100)
        previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
        self.view.layer.addSublayer(previewLayer)
    
        let btn = UIButton()
        btn.setTitle("Back", forState: .Normal)
        btn.setTitleColor(UIColor.redColor(), forState: .Normal)
        btn.sizeToFit()
        frame = btn.frame
        frame.origin.y = 25
        btn.frame = frame
        self.view.addSubview(btn)
        btn.addTarget(self, action: "back:", forControlEvents: .TouchUpInside)
      }
    
      func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!){
    
        let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
    
        CVPixelBufferLockBaseAddress(imageBuffer, 0)
    
        let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer)
        let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer)
        let width = CVPixelBufferGetWidth(imageBuffer)
        let height = CVPixelBufferGetHeight(imageBuffer)
    
        let colorSpace = CGColorSpaceCreateDeviceRGB()
    //    let bmpInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue|CGBitmapInfo.ByteOrder32Little.rawValue)
        let newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedFirst.rawValue|CGBitmapInfo.ByteOrder32Little.rawValue)
        let newImage = CGBitmapContextCreateImage(newContext)
    
        customLayer.performSelectorOnMainThread("setContents:", withObject: newImage, waitUntilDone: true)
    
        let image = UIImage(CGImage: newImage!, scale: 1.0, orientation: UIImageOrientation.Right)
        imageView.performSelectorOnMainThread("setImage:", withObject: image, waitUntilDone: true)
    
        CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
      }
    
      func back(sender:AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)
      }
    
      override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        captureSession.stopRunning()
      }
    }
    
    展开全文
  • iOS10 权限崩溃问题  今天 升级了 xcode8,然后用正在开发的项目 运行,发现点击有关 权限访问 直接Crash了,并在控制台输出了一些信息: This app has crashed because it attempted to access privacy-...

    iOS10 权限崩溃问题

           今天 升级了 xcode8,然后用正在开发的项目 运行,发现点击有关 权限访问 直接Crash了,并在控制台输出了一些信息:

    This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSContactsUsageDescription key with a string value explaining to the user how the app uses this data.

    意思是说:你需要在info.plist文件 添加一个“NSContactsUsageDescription ”的Key,Value添加一个描述。


    1,在项目中找到info.plist文件,右击有个 Open As,以Source Code 的形式打开

    2,分别复制 以下 Value 和Key,Key 一定不能错,Value 貌似可以随便填写


    相机权限描述:

        <key>NSCameraUsageDescription</key>
        <string>cameraDesciption</string>

    通信录:
        <key>NSContactsUsageDescription</key>
        <string>contactsDesciption</string>

    麦克风:
        <key>NSMicrophoneUsageDescription</key>
        <string>microphoneDesciption</string>

    相机:
        <key>NSPhotoLibraryUsageDescription</key>
        <string>photoLibraryDesciption</string>


    eg:其他权限描述,debug 控制台都会有输出的,自行添加就OK

    3,在info.plist 文件上 复制上,然后 保存,如下图:

    Source Code 的形式:



    Property List 的展现形式:



    4,Clean之后,运行就OK了

    展开全文
  • iOS 10 适配 相机

    2016-09-22 11:29:13
    升级 iOS 10 之后,发现调用相机,崩了。试试看调用相册,又特么崩了。然后看到控制台输出了以下信息: This app has crashed because it attempted to access privacy-sensitive data without a usage description....

    升级 iOS 10 之后,发现调用相机,崩了。试试看调用相册,又特么崩了。然后看到控制台输出了以下信息:

    This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

    意思就是说,你需要在 info.plist 文件添加一个 NSPhotoLibraryUsageDescription的 key,然后添加一个描述。

    解决方案
    1.在项目中找到info.plist文件,右键点击以 Source Code形式打开
    2.添加以下键值对,这里以 PhotoLibrary 作为例子

        <key>NSPhotoLibraryUsageDescription</key>
        <string>此 App 需要您的同意才能读取媒体资料库</string>

    注意,key 是绝对不能写错的,

    而 value 也就是<string></string>你可以随意写


    目测所有需要的权限描述都会在 iOS 10 beta里面crash,不用怕,控制台会有输出的,自行添加就 OK,我另外附送几个 key/value 给你们

        <key>NSCameraUsageDescription</key>    
        <string>cameraDesciption</string>
    
        <key>NSContactsUsageDescription</key>    
        <string>contactsDesciption</string>
    
        <key>NSMicrophoneUsageDescription</key>    
        <string>microphoneDesciption</string>

    嗯,然后 clean 一下,重新运行。

    当然我比较推荐的做法是直接
    info.plist 还是用 Property List 的形式,然后点击添加, 就是滑动到最后一个 item 会出现一个小加号
    输入 Privacy 可以迅速定位到这一权限系列,找到你需要的权限,修改后面的 value 就可以了



    展开全文
  • 今天在写一个关于人脸识别的demo时,发现相机相册调取不了。忽然想起来工程info.plist里边需要设置两个参数,但是就是想不起来参数叫什么。网上搜了好一会儿才找到,所以就写篇文字,记录一下,方便以后查找。 想...
  • ios10相机权限设置 ios10调用相机直接导至应用crash. 解决办法:找到info.plist文件,添加权限: 相机: NSCameraUsageDescription  cameraDesciption 相册: NSPhotoLibraryUsageDescription  ...
  • 相信大家开发自定义相机的时候都有碰到过 相机怎么自定对焦。 百度查找到的一般都是检查照片的模糊度。其实不用这么麻烦苹果有自带的方法。 不多说附上代码 /**  * AVCaptureSession对象来执行输入设备和输出...
  • iOS相机相册使用权限

    2016-12-10 08:11:44
    NSPhotoLibraryUsageDescription App需要您的同意,才能访问相册 NSCameraUsageDescription App需要您的同意,才能访问相机 NSMicrophoneUsageDescription App需要您的同意,才能访问麦克风 ...
  • iOS 相机打开动画效果

    2015-11-03 21:39:09
    - (void)addHollowOpenToView:(UIView *)view { //注释掉拍照的动画   CATransition *animation = [CATransition animation];  animation.duration = 0.5f;  animation.delegate = ...
  • 想做个相机调用做个混编总结,然后回传照片给Flutter。 flutter没有UIImage对应的类型,就是说回调时直接回传UIImage时报错,说没有此类型,Flutter和NA互调信息都是走的字节流。然后把UIimage转成NSData类型回传,...
  • iOS10之后对相机和相册访问有了更为严格的控制,未做iOS10适配的app在升级iOS10系统之后,相机或相册访问时会闪退在info.plist中加入相册和相机使用描述字段即可具体操作:右键点击info.plist选择open as->source ...
  • iOS 相机实时滤镜效果

    2019-06-11 22:45:34
    前言 项目Demo,实现了实时滤镜、拍照、录像功能。 最近玩了哈实时滤镜,学到挺多东西的。笔者长得丑,看看有没有机会没那么丑。只挑了几种滤镜,笔者是个钢铁直男,没有美颜效果。 原理 设备获取图像输入流后,经过...
  • 30分钟搞定iOS自定义相机 字数1490 阅读1126 评论11 喜欢84  最近公司的项目中用到了相机,由于不用系统的相机,UI给的相机切图,必须自定义才可以。就花时间简单研究了一下相机的自定义。  相机属于...
  • 微信小程序单页面-模拟IOS相机页面virtualCamera-master.zip
  • iOS10 权限崩溃问题  今天 手机升级了 iOS10 Beta,然后用正在开发的项目 装了个ipa包,发现点击有关 权限访问 直接Crash了,并在控制台输出了一些信息: This app has crashed because it attempted to ...
  • iOS相机选择器

    2015-12-07 13:54:22
    iOS相机选择器, 封装相机的所有操作.
  • iOS中 自定义系统相机 作者:韩俊强 实现:拍照/闪光灯自动开闭/聚焦光圈等相关功能! 百度搜"韩俊强iOS"了解更多......
  • 所以为了解决这个问题,自己想出的方法是获取IOS上相机权限的状态,在Unity端通过获取到ios相机权限的状态进行处理,未开启权限给与提示让用户提供权限再进行游戏。 所以为了解决这个问题,自己通过咨询发现需要...
  • 类似于iOS相机滑动切换的View
1 2 3 4 5 ... 20
收藏数 21,256
精华内容 8,502