Manos Chorianopoulos

add barcode lib

......@@ -15,6 +15,7 @@
1E879E27281AC99F0089F489 /* OldCouponsViewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E879E26281AC99F0089F489 /* OldCouponsViewInterface.swift */; };
1E98EC1428199C4F007524A0 /* AllGiftsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E98EC1328199C4F007524A0 /* AllGiftsView.swift */; };
1E98EC1628199C86007524A0 /* AllGiftsViewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E98EC1528199C86007524A0 /* AllGiftsViewInterface.swift */; };
1EBB036F281BE3610062F663 /* RSBarcodes_Swift in Frameworks */ = {isa = PBXBuildFile; productRef = 1EBB036E281BE3610062F663 /* RSBarcodes_Swift */; };
1EBEB02D280D69D800BF802C /* GiftsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBEB02C280D69D800BF802C /* GiftsView.swift */; };
1EBEB02F280D6AA500BF802C /* GiftsViewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBEB02E280D6AA500BF802C /* GiftsViewInterface.swift */; };
260C6A1AFF7560C32E212F20 /* Pods_WarplySDKFrameworkIOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1353B8C484CC0649CAC2EB74 /* Pods_WarplySDKFrameworkIOS.framework */; };
......@@ -292,6 +293,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1EBB036F281BE3610062F663 /* RSBarcodes_Swift in Frameworks */,
260C6A1AFF7560C32E212F20 /* Pods_WarplySDKFrameworkIOS.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -671,6 +673,9 @@
dependencies = (
);
name = WarplySDKFrameworkIOS;
packageProductDependencies = (
1EBB036E281BE3610062F663 /* RSBarcodes_Swift */,
);
productName = WarplySDKFrameworkIOS;
productReference = E6D8DE6827A942010006A3A9 /* WarplySDKFrameworkIOS.framework */;
productType = "com.apple.product-type.framework";
......@@ -699,6 +704,9 @@
Base,
);
mainGroup = E6D8DE5E27A942000006A3A9;
packageReferences = (
1EBB036D281BE3610062F663 /* XCRemoteSwiftPackageReference "RSBarcodes_Swift" */,
);
productRefGroup = E6D8DE6927A942010006A3A9 /* Products */;
projectDirPath = "";
projectRoot = "";
......@@ -1045,6 +1053,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
1EBB036D281BE3610062F663 /* XCRemoteSwiftPackageReference "RSBarcodes_Swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/yeahdongcn/RSBarcodes_Swift";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
1EBB036E281BE3610062F663 /* RSBarcodes_Swift */ = {
isa = XCSwiftPackageProductDependency;
package = 1EBB036D281BE3610062F663 /* XCRemoteSwiftPackageReference "RSBarcodes_Swift" */;
productName = RSBarcodes_Swift;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = E6D8DE5F27A942010006A3A9 /* Project object */;
}
......
{
"object": {
"pins": [
{
"package": "RSBarcodes_Swift",
"repositoryURL": "https://github.com/yeahdongcn/RSBarcodes_Swift",
"state": {
"branch": null,
"revision": "86d8b1a1439e7edb19793d17732b15fd784a0a15",
"version": "5.1.1"
}
}
]
},
"version": 1
}
......@@ -10,8 +10,8 @@ import SwiftUI
import Combine
import Foundation
import UIKit
// import RSBarcodes_Swift
// import AVFoundation
import RSBarcodes_Swift
import AVFoundation
......@@ -95,35 +95,6 @@ extension CouponBarcodeView {
}
func generateBarcode(from string: String) -> Image? {
let data = string.data(using: String.Encoding.ascii)
if let filter = CIFilter(name: "CICode128BarcodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
// let transform = CGAffineTransform(scaleX: 3, y: 3)
// if let output = filter.outputImage?.transformed(by: transform) {
if let output = filter.outputImage {
// // Change the color using CIFilter
// let colorParameters = [
// "inputColor0": CIColor(color: UIColor.black), // Foreground
// "inputColor1": CIColor(color: UIColor.clear) // Background
// ]
// let colored = output.applyingFilter("CIFalseColor", parameters: colorParameters)
let image = Image(uiImage: UIImage(ciImage: output))
// return UIImage(ciImage: output)
return image
}
}
return nil
}
func constructBarcode() -> String? {
// EAN 13 barcode construction
let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
......@@ -161,6 +132,7 @@ extension CouponBarcodeView {
var body: some View {
let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
let barcodeString = constructBarcode() ?? ""
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
......@@ -222,45 +194,23 @@ extension CouponBarcodeView {
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.015)
// TODO: Add the barcode
// Image(uiImage: UIImage(ciImage: output))
// let isValid = RSUnifiedCodeValidator.shared.isValid("1234567891234", machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue)
// let isValid = RSUnifiedCodeValidator.shared.isValid(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue)
// if let barcodeImage = RSUnifiedCodeGenerator.shared.generateCode("1234567891234", machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: 300, height: 300)) {
if let barcodeImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.1)) {
// VStack(alignment: .center) {
// Image(uiImage: image)
// .resizable()
// .aspectRatio(contentMode: .fit)
// .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.05)
//
// }
// .frame(maxWidth: .infinity)
// .padding(.top, self.uiscreen.height * 0.01)
// Image(uiImage: UIImage(named: "ic_back")!)
// .renderingMode(.original)
// .resizable()
// .aspectRatio(contentMode: .fit)
// .frame(width: 300, height: 300)
// Image(uiImage: barcodeImage)
// .renderingMode(.original)
// .resizable()
// .aspectRatio(contentMode: .fit)
// .frame(width: 300, height: 300)
// .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.05)
// }
VStack(alignment: .center) {
Image(uiImage: barcodeImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.1)
}
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.01)
}
// generateBarcode(from: "1234567891234")
// ?
// .resizable()
// .aspectRatio(contentMode: .fit)
// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
Text(constructBarcode() ?? "")
Text(barcodeString)
.fontWeight(.regular)
.font(.system(size: 22))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
......