QRCode--根据系统API, 封装二维码扫描
2016-02-02 13:57
246 查看
QRCode
根据系统API, 封装二维码扫描代码:https://github.com/whde/QRCode
- 1.link AVFoundation.framework
2.#import
/*! * 扫一扫 */ - (void)intoQRCodeVC { NSString *mediaType = AVMediaTypeVideo; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; if(authStatus == AVAuthorizationStatusDenied){ if (IS_VAILABLE_IOS8) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"相机权限受限" message:@"请在iPhone的\"设置->隐私->相机\"选项中,允许\"自游邦\"访问您的相机." preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]]; [alert addAction:[UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if ([self canOpenSystemSettingView]) { [self systemSettingView]; } }]]; [self presentViewController:alert animated:YES completion:nil]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"相机权限受限" message:@"请在iPhone的\"设置->隐私->相机\"选项中,允许\"自游邦\"访问您的相机." delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil]; [alert show]; } return; } QRCodeController *qrcodeVC = [[QRCodeController alloc] init]; qrcodeVC.view.alpha = 0; [qrcodeVC setDidReceiveBlock:^(NSString *result) { NSLog(@"%@", result); }]; AppDelegate *del = (AppDelegate *)[UIApplication sharedApplication].delegate; [del.window.rootViewController addChildViewController:qrcodeVC]; [del.window.rootViewController.view addSubview:qrcodeVC.view]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ qrcodeVC.view.alpha = 1; } completion:^(BOOL finished) { }]; } /** * 是否可以打开设置页面 * * @return */ - (BOOL)canOpenSystemSettingView { if (IS_VAILABLE_IOS8) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { return YES; } else { return NO; } } else { return NO; } } /** * 跳到系统设置页面 */ - (void)systemSettingView { if (IS_VAILABLE_IOS8) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } } }
相关文章推荐
- 快排模板
- Sql操作之二:不同数据库中表数据迁移
- Android图片处理内存溢出
- Quartz1.8.5例子(四)
- Javascript 中使用Json的四种途径
- ROS进阶学习笔记(11)- Turtlebot Navigation and SLAM
- 【转】珍藏多年的素材,灵感搜寻网站
- LoadRunner的参数化保证不重复
- 0007-eclipse+OpenExplore
- poj2513 Colored Sticks(欧拉回路判断+字典树)
- Android实现简单音乐播放器(MediaPlayer)
- 查找二叉树的C++代码实现
- 使用powerdesigner导入sql文件查看er模型图
- uva11520 - Fill the Square
- SQL SERVER中强制类型转换cast和convert的区别
- Android-Universal-Image-Loader异步加载图片框架学习研究
- Java class文件分析工具 -- Classpy
- python基础知识学习:列表和元组
- v$log and v$logfile
- Windows2003计划任务设置操作手册