Parcourir la source

1.修改iOS Apex Drivers相机权限检查。

Pen Li il y a 7 ans
Parent
commit
f79d3fee74

+ 25 - 0
Redant Drivers/Apex And Drivers/Camera/RACameraViewController.m

@@ -90,10 +90,35 @@
 
 #pragma mark - Capture
 
+- (BOOL)camerAuthorization {
+    
+    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
+    if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied) {
+        return NO;
+    }
+    return YES;
+}
+
+
 - (void)initCapture {
     
     self.cameraInitial = NO;
     
+    if (![self camerAuthorization]) {
+        
+        NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
+        NSString *appName = [infoDict objectForKey:@"CFBundleName"];
+        __weak typeof(self) weakSelf = self;
+        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            [weakSelf dismissViewControllerAnimated:YES completion:nil];
+        }];
+        [alert addAction:action];
+        [self presentViewController:alert animated:YES completion:nil];
+        
+        return;
+    }
+    
     self.captureSession = [[AVCaptureSession alloc] init];
     
     self.captureDevice = [self videoDevicePosition:AVCaptureDevicePositionBack];

+ 20 - 16
Redant Drivers/Apex And Drivers/QRCode/QRCode.storyboard

@@ -45,9 +45,12 @@
                                     </mask>
                                 </variation>
                             </view>
-                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0ig-dn-iSa">
-                                <rect key="frame" x="621" y="192" width="35" height="30"/>
-                                <state key="normal" title="Scan"/>
+                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0ig-dn-iSa">
+                                <rect key="frame" x="596" y="177" width="60" height="60"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="60" id="OkG-xs-m3c"/>
+                                    <constraint firstAttribute="width" secondItem="0ig-dn-iSa" secondAttribute="height" multiplier="1:1" id="ZrC-2n-5ix"/>
+                                </constraints>
                                 <connections>
                                     <action selector="scannerBtnTouchCancel:" destination="41J-NQ-wiU" eventType="touchCancel" id="z40-QN-qDW"/>
                                     <action selector="scannerBtnTouchDown:" destination="41J-NQ-wiU" eventType="touchDown" id="5TK-sG-LzS"/>
@@ -93,77 +96,78 @@
                         <variation key="default">
                             <mask key="constraints">
                                 <exclude reference="7a1-vL-ZwM"/>
-                                <exclude reference="7eW-A7-Nkb"/>
-                                <exclude reference="cSr-ne-Xxd"/>
-                                <exclude reference="eCS-j2-u7d"/>
-                                <exclude reference="exY-By-XcQ"/>
-                                <exclude reference="qin-xY-VOb"/>
-                                <exclude reference="uOO-Nq-OMU"/>
                                 <exclude reference="8dy-2H-2iw"/>
                                 <exclude reference="V3j-Mb-G9g"/>
                                 <exclude reference="Z6F-qY-EEv"/>
+                                <exclude reference="cSr-ne-Xxd"/>
                                 <exclude reference="e2p-ZK-jAC"/>
                                 <exclude reference="fNO-9Q-eMD"/>
                                 <exclude reference="gDV-MG-Lxf"/>
                                 <exclude reference="mwH-jr-Ixq"/>
                                 <exclude reference="ncF-ii-QJ5"/>
                                 <exclude reference="s29-TR-Yol"/>
+                                <exclude reference="uOO-Nq-OMU"/>
                                 <exclude reference="29i-AW-HSH"/>
                                 <exclude reference="3gR-v0-uuY"/>
+                                <exclude reference="7eW-A7-Nkb"/>
                                 <exclude reference="7qf-eL-rnv"/>
                                 <exclude reference="DcB-0a-gGt"/>
                                 <exclude reference="R8a-93-kVx"/>
                                 <exclude reference="Vi4-ET-WmZ"/>
+                                <exclude reference="eCS-j2-u7d"/>
+                                <exclude reference="exY-By-XcQ"/>
+                                <exclude reference="qin-xY-VOb"/>
                             </mask>
                         </variation>
                         <variation key="heightClass=compact-widthClass=compact">
                             <mask key="constraints">
                                 <include reference="7a1-vL-ZwM"/>
-                                <include reference="7eW-A7-Nkb"/>
                                 <include reference="Z6F-qY-EEv"/>
                                 <include reference="gDV-MG-Lxf"/>
                                 <include reference="29i-AW-HSH"/>
+                                <include reference="7eW-A7-Nkb"/>
                                 <include reference="DcB-0a-gGt"/>
                             </mask>
                         </variation>
                         <variation key="heightClass=compact-widthClass=regular">
                             <mask key="constraints">
-                                <include reference="eCS-j2-u7d"/>
-                                <include reference="uOO-Nq-OMU"/>
                                 <include reference="V3j-Mb-G9g"/>
                                 <include reference="mwH-jr-Ixq"/>
+                                <include reference="uOO-Nq-OMU"/>
                                 <include reference="R8a-93-kVx"/>
+                                <include reference="eCS-j2-u7d"/>
                             </mask>
                         </variation>
                         <variation key="heightClass=regular-widthClass=compact">
                             <mask key="constraints">
-                                <include reference="cSr-ne-Xxd"/>
-                                <include reference="qin-xY-VOb"/>
                                 <include reference="8dy-2H-2iw"/>
+                                <include reference="cSr-ne-Xxd"/>
                                 <include reference="fNO-9Q-eMD"/>
                                 <include reference="ncF-ii-QJ5"/>
                                 <include reference="3gR-v0-uuY"/>
                                 <include reference="Vi4-ET-WmZ"/>
+                                <include reference="qin-xY-VOb"/>
                             </mask>
                         </variation>
                         <variation key="heightClass=regular-widthClass=regular">
                             <mask key="constraints">
-                                <include reference="exY-By-XcQ"/>
                                 <include reference="e2p-ZK-jAC"/>
                                 <include reference="s29-TR-Yol"/>
                                 <include reference="7qf-eL-rnv"/>
+                                <include reference="exY-By-XcQ"/>
                             </mask>
                         </variation>
                     </view>
                     <connections>
                         <outlet property="maskView" destination="4DJ-GK-9l9" id="naM-uL-H99"/>
                         <outlet property="previewContainer" destination="D8z-rA-Qpf" id="XCg-1T-zSa"/>
+                        <outlet property="scanBtn" destination="0ig-dn-iSa" id="JUa-KJ-cvr"/>
                         <outlet property="scanerView" destination="vCI-Zm-N7X" id="09n-Fn-vIF"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="3tF-Yn-TdS" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
-            <point key="canvasLocation" x="-155.07246376811597" y="161.41304347826087"/>
+            <point key="canvasLocation" x="-155.70652173913044" y="160.86956521739131"/>
         </scene>
     </scenes>
 </document>

+ 50 - 0
Redant Drivers/Apex And Drivers/QRCode/RAQRCodeScannerViewController.m

@@ -14,6 +14,7 @@
 @property (strong, nonatomic) IBOutlet UIView *scanerView;
 @property (nonatomic,strong) IBOutlet UIView *previewContainer;
 @property (strong, nonatomic) IBOutlet UIView *maskView;
+@property (strong, nonatomic) IBOutlet UIButton *scanBtn;
 
 @property (nonatomic,strong) AVCaptureDevice *device;
 @property (nonatomic,strong) AVCaptureDeviceInput *input;
@@ -48,6 +49,12 @@
     self.scanerView.layer.borderColor = [UIColor blackColor].CGColor;
     self.scanerView.layer.borderWidth = 0.5f;
     
+    UIImage *normal_img = [self.class imageWithColor:[UIColor redColor] Size:CGSizeMake(60, 60)];
+    UIImage *highlight_img = [self.class imageWithColor:[UIColor greenColor] Size:CGSizeMake(60, 60)];
+    
+    [self.scanBtn setImage:normal_img forState:UIControlStateNormal];
+    [self.scanBtn setImage:highlight_img forState:UIControlStateHighlighted];
+    
     [self initCapture];
 }
 
@@ -194,6 +201,22 @@
 - (void)initCapture {
     
     self.scannerInitial = NO;
+    
+    if (![self camerAuthorization]) {
+        
+        NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
+        NSString *appName = [infoDict objectForKey:@"CFBundleName"];
+        __weak typeof(self) weakSelf = self;
+        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            [weakSelf dismissViewControllerAnimated:YES completion:nil];
+        }];
+        [alert addAction:action];
+        [self presentViewController:alert animated:YES completion:nil];
+        
+        return;
+    }
+    
     self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
     
     NSError *inputError;
@@ -241,6 +264,15 @@
     self.scannerInitial = YES;
 }
 
+- (BOOL)camerAuthorization {
+    
+    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
+    if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied) {
+        return NO;
+    }
+    return YES;
+}
+
 #pragma mark - AVCaptureMetadataOutputObjectsDelegate
 
 - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
@@ -280,4 +312,22 @@
     self.scannerEnable = NO;
 }
 
+#pragma mark - Utils
+
++ (UIImage *)imageWithColor:(UIColor *)color Size:(CGSize)size {
+    
+    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
+    CGContextRef ctx = UIGraphicsGetCurrentContext();
+    CGContextAddEllipseInRect(ctx, CGRectMake(5, 5, size.width - 10, size.height - 10));
+    CGContextSetFillColorWithColor(ctx, color.CGColor);
+    CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
+    CGContextSetLineWidth(ctx, 3.0f);
+    CGContextDrawPath(ctx, kCGPathFillStroke);
+    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
+    UIGraphicsEndImageContext();
+    
+    return img;
+}
+
+
 @end