Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release ios 3.0 #16

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8ed844f
:
Jun 2, 2021
53b8fc1
#addeded
Jun 2, 2021
c0329d9
Create README.md
dineshkokare56 Jun 2, 2021
996925c
add new commit.
Jun 3, 2021
a4a0ff2
Added method.
Jun 4, 2021
ef44ff2
method added.
Jun 4, 2021
a5c00e1
startscanner method parameter added.
Jun 4, 2021
cb7aff2
added path.
Jun 4, 2021
b803eed
added
Jun 4, 2021
14f50bf
added
Jun 4, 2021
8d2d872
Added new code.
dineshkokare56 Jun 7, 2021
e5bf22a
Update QRScannerPlugin.swift
dineshkokare56 Jun 7, 2021
8c8b3d6
added method in plugin.
dineshkokare56 Jun 7, 2021
3e404b7
added comment.
dineshkokare56 Jun 8, 2021
548754e
added.
dineshkokare56 Jun 8, 2021
1a3f3a4
Update QRScannerPlugin.swift
dineshkokare56 Jun 8, 2021
a27132f
added line of code.
dineshkokare56 Jun 8, 2021
260a961
added ios commit.
dineshkokare56 Jun 9, 2021
df84f65
added ios commit.
dineshkokare56 Jun 9, 2021
caf4a82
Update QRScannerPlugin.swift
dineshkokare56 Jun 10, 2021
14045ce
Update QRScannerPlugin.swift
dineshkokare56 Jun 10, 2021
b5d7d99
Update QRScannerPlugin.swift
dineshkokare56 Jun 11, 2021
6ab7ec1
added method of QRScannerPlugin.
dineshkokare56 Jun 11, 2021
1ab84e6
added all method and functionality in plugin.
dineshkokare56 Jun 11, 2021
da2ecc6
added method and functionality in QRScannerPlugin.swift.
dineshkokare56 Jun 11, 2021
c75b431
added.
dineshkokare56 Jun 11, 2021
41f5712
added method comment.
dineshkokare56 Jun 11, 2021
9c90a8e
Update QRScannerPlugin.swift
dineshkokare56 Jun 11, 2021
d2694dd
added.
dineshkokare56 Jun 11, 2021
b9ace4e
added commit.
dineshkokare56 Jun 11, 2021
8ead54c
Update QRScannerPlugin.swift
dineshkokare56 Jun 11, 2021
fdf25ae
# Your branch is up to date with 'origin/release-ios-3.0'.
dineshkokare56 Jun 11, 2021
5880c4c
Update QRScannerPlugin.swift
dineshkokare56 Jun 16, 2021
7a7c018
Update QRScannerPlugin.swift
dineshkokare56 Jun 16, 2021
6132e4e
Update QRScannerPlugin.swift
dineshkokare56 Jun 17, 2021
b187aef
added coded.
dineshkokare56 Jun 17, 2021
2f27c54
Update QRScannerPlugin.swift
dineshkokare56 Jun 18, 2021
d9ce5e9
added to code.
dineshkokare56 Jun 18, 2021
da2744c
Update QRScannerPlugin.swift
dineshkokare56 Jun 18, 2021
fb45055
added method.
dineshkokare56 Jun 18, 2021
b834beb
Update QRScannerPlugin.swift
dineshkokare56 Jun 18, 2021
dccde82
added .
dineshkokare56 Jun 18, 2021
225af0f
addeded.
dineshkokare56 Jun 21, 2021
882a3dd
added.
dineshkokare56 Jun 21, 2021
6037538
Update QRScannerPlugin.swift
dineshkokare56 Jun 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cordova-plugin-qr-scanner
Cordova plugin for QR code scanner
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"platforms": [
"android",
"ios"

]
},
"description": "A starting point for a Cordova Plugin"
Expand Down
10 changes: 10 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@
<resource-file src="res/drawable-xxhdpi/ic_action_arrow_right.png" target="res/drawable-xxhdpi/ic_action_arrow_right.png" />
<resource-file src="res/layout/qr_scanner_dialog.xml" target="res/layout/qr_scanner_dialog.xml" />
</platform>

<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="qrScanner">
<param name="ios-package" value="qrScanner" />
</feature>
</config-file>
<source-file src="src/ios/QRScannerPlugin.swift" />
</platform>
</plugin>
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/ios/.DS_Store
Binary file not shown.
185 changes: 185 additions & 0 deletions src/ios/QRScannerPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import Foundation
import AVFoundation

@author DineshKokare

@objc(QRScannerPlugin) class QRScannerPlugin : CDVPlugin,AVCaptureMetadataOutputObjectsDelegate {

class CameraView: UIView {
var videoPreviewLayer:AVCaptureVideoPreviewLayer?

//Interface Method.:
func interfaceOrientationToVideoOrientation(_ orientation : UIInterfaceOrientation) -> AVCaptureVideoOrientation {
switch (orientation) {
case UIInterfaceOrientation.portrait:
return AVCaptureVideoOrientation.portrait;
case UIInterfaceOrientation.portraitUpsideDown:
return AVCaptureVideoOrientation.portraitUpsideDown;
case UIInterfaceOrientation.landscapeLeft:
return AVCaptureVideoOrientation.landscapeLeft;
case UIInterfaceOrientation.landscapeRight:
return AVCaptureVideoOrientation.landscapeRight;
default:
return AVCaptureVideoOrientation.portraitUpsideDown;
}
}

override func layoutSubviews() {
super.layoutSubviews();
if let sublayers = self.layer.sublayers {
for layer in sublayers {
layer.frame = self.bounds;
}
}

self.videoPreviewLayer?.connection?.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation);
}

func addPreviewLayer(_ previewLayer:AVCaptureVideoPreviewLayer?) {
previewLayer!.videoGravity = AVLayerVideoGravity.resizeAspectFill
previewLayer!.frame = self.bounds
self.layer.addSublayer(previewLayer!)
self.videoPreviewLayer = previewLayer;
}

func removePreviewLayer() {
if self.videoPreviewLayer != nil {
self.videoPreviewLayer!.removeFromSuperlayer()
self.videoPreviewLayer = nil
}
}
}

var cameraView: CameraView!
var captureSession:AVCaptureSession?
var captureVideoPreviewLayer:AVCaptureVideoPreviewLayer?
var metaOutput: AVCaptureMetadataOutput?

var currentCamera: Int = 0;
var frontCamera: AVCaptureDevice?
var backCamera: AVCaptureDevice?

var scanning: Bool = false
var paused: Bool = false
var nextScanningCommand: CDVInvokedUrlCommand?

enum QRScannerError: Int32 {
case unexpected_error = 0,
camera_access_denied = 1,
camera_access_restricted = 2,
back_camera_unavailable = 3,
front_camera_unavailable = 4,
camera_unavailable = 5,
scan_canceled = 6,
light_unavailable = 7,
open_settings_unavailable = 8
}

enum CaptureError: Error {
case backCameraUnavailable
case frontCameraUnavailable
case couldNotCaptureInput(error: NSError)
}

enum LightError: Error {
case torchUnavailable
}

override func pluginInitialize() {
super.pluginInitialize()
NotificationCenter.default.addObserver(self, selector: #selector(pageDidLoad), name: NSNotification.Name.CDVPageDidLoad, object: nil)
self.cameraView = CameraView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
self.cameraView.autoresizingMask = [.flexibleWidth, .flexibleHeight];
}

func sendErrorCode(command: CDVInvokedUrlCommand, error: QRScannerError){
let pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: error.rawValue)
commandDelegate!.send(pluginResult, callbackId:command.callbackId)
}

// utility method
@objc func backgroundThread(delay: Double = 0.0, background: (() -> Void)? = nil, completion: (() -> Void)? = nil) {
if #available(iOS 8.0, *) {
DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async {
if (background != nil) {
background!()
}
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay * Double(NSEC_PER_SEC)) {
if(completion != nil){
completion!()
}
}
}
} else {
// Fallback for iOS < 8.0
if(background != nil){
background!()
}
if(completion != nil){
completion!()
}
}
}


@objc(qrScanner:)
func qrScanner (_ command: CDVInvokedUrlCommand,_ commond: startScanner,_ commond: stopScanner){
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "")
commandDelegate!.send(pluginResult, callbackId:command.callbackId)

}
//Check method for startscanner and stopscanner.
func boolean execute(Action:String, JSONArray:[args]) -> bool{
if (action.equals(ACTION_QR_SCANNER)){
String type = args.String(0)
switch (type) {

case START_SCANNING:
startScanner();
break;

case STOP_SCANNING:
stopScanner();

break;

}
}
return true

}

// startScanner Method.
@objc(startScanner:)

func startScanner(_ command: CDVInvokedUrlCommand) {
var pluginResult:CDVPluginResult = CDVPluginResult.init(status: CDVCommandStatus_ERROR)
let startScanner = command.arguments[0] as? String ?? ""
let screenTitle = command.arguments[1] as? String ?? "Scan QR Code."
let displayText = command.arguments[2] as? String ?? "Point your phone to the QR code to scan it"
let displayTextColor = command.arguments[3] as? String ?? "0b0b0b"
let buttonText = command.arguments[4] as? String ?? "I don't have a QR Code"
let showButton = command.arguments[5] as? Bool ?? false
let isRtl = command.arguments[6] as? Bool ?? false

print("Start Scanning Successfully.")
pluginResult = CDVPluginResult.init(status: CDVCommandStatus_OK, messageAs: "Start Scanning Successfully.")
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)

}

}

// stopScanner Method.
@objc(stopScanner:)
func stopScanner(_ command: CDVInvokedUrlCommand) {

print("Stop Scanning Successfully.")

let pluginResult:CDVPluginResult = CDVPluginResult.init(status: CDVCommandStatus_OK, messageAs: "Stop Scanning Successfully.")
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)

}