@@ -648,6 +648,133 @@ - (void)lastAttributedTouchData:(CDVInvokedUrlCommand *)command {
648
648
}];
649
649
}
650
650
651
+ - (void )getBranchQRCode : (CDVInvokedUrlCommand*)command
652
+ {
653
+ int branchUniversalObjectId = [[command.arguments objectAtIndex: 1 ] intValue ];
654
+ NSMutableDictionary *branchUniversalObjDict = [self .branchUniversalObjArray objectAtIndex: branchUniversalObjectId];
655
+ BranchUniversalObject *branchUniversalObj = [branchUniversalObjDict objectForKey: @" branchUniversalObj" ];
656
+ // BranchUniversalObject *branchUniversalObj = [BranchUniversalObject new];//[[BranchUniversalObject alloc] initWithMap:universalObjectProperties];
657
+
658
+ BranchLinkProperties *linkProperties = [BranchLinkProperties new ];// [self createLinkProperties:linkPropertiesMap withControlParams:controlParamsMap];
659
+
660
+ NSDictionary *arg1 = [command.arguments objectAtIndex: 2 ];
661
+ NSDictionary *arg2 = [command.arguments objectAtIndex: 3 ];
662
+
663
+ for (id key in arg1) {
664
+ if ([key isEqualToString: @" duration" ]) {
665
+ linkProperties.matchDuration = (NSUInteger )[((NSNumber *)[arg1 objectForKey: key]) integerValue ];
666
+ }
667
+ else if ([key isEqualToString: @" feature" ]) {
668
+ linkProperties.feature = [arg1 objectForKey: key];
669
+ }
670
+ else if ([key isEqualToString: @" stage" ]) {
671
+ linkProperties.stage = [arg1 objectForKey: key];
672
+ }
673
+ else if ([key isEqualToString: @" campaign" ]) {
674
+ linkProperties.campaign = [arg1 objectForKey: key];
675
+ }
676
+ else if ([key isEqualToString: @" alias" ]) {
677
+ linkProperties.alias = [arg1 objectForKey: key];
678
+ }
679
+ else if ([key isEqualToString: @" channel" ]) {
680
+ linkProperties.channel = [arg1 objectForKey: key];
681
+ }
682
+ else if ([key isEqualToString: @" tags" ] && [[arg1 objectForKey: key] isKindOfClass: [NSArray class ]]) {
683
+ linkProperties.tags = [arg1 objectForKey: key];
684
+ }
685
+ }
686
+ if (arg2) {
687
+ for (id key in arg2) {
688
+ [linkProperties addControlParam: key withValue: [arg2 objectForKey: key]];
689
+ }
690
+ }
691
+
692
+
693
+ NSMutableDictionary *qrCodeSettingsMap = [command.arguments objectAtIndex: 0 ];
694
+
695
+ BranchQRCode *qrCode = [BranchQRCode new ];
696
+
697
+ if (qrCodeSettingsMap[@" codeColor" ]) {
698
+ qrCode.codeColor = [self colorWithHexString: qrCodeSettingsMap[@" codeColor" ]];
699
+ }
700
+ if (qrCodeSettingsMap[@" backgroundColor" ]) {
701
+ qrCode.backgroundColor = [self colorWithHexString: qrCodeSettingsMap[@" backgroundColor" ]];
702
+ }
703
+ if (qrCodeSettingsMap[@" centerLogo" ]) {
704
+ qrCode.centerLogo = qrCodeSettingsMap[@" centerLogo" ];
705
+ }
706
+ if (qrCodeSettingsMap[@" width" ]) {
707
+ qrCode.width = qrCodeSettingsMap[@" width" ];
708
+ }
709
+ if (qrCodeSettingsMap[@" margin" ]) {
710
+ qrCode.margin = qrCodeSettingsMap[@" margin" ];
711
+ }
712
+ if (qrCodeSettingsMap[@" imageFormat" ]) {
713
+ if ([qrCodeSettingsMap[@" imageFormat" ] isEqual: @" JPEG" ]) {
714
+ qrCode.imageFormat = BranchQRCodeImageFormatJPEG;
715
+ } else {
716
+ qrCode.imageFormat = BranchQRCodeImageFormatPNG;
717
+ }
718
+ }
719
+
720
+ [qrCode getQRCodeAsData: branchUniversalObj linkProperties: linkProperties completion: ^(NSData * _Nonnull qrCodeData, NSError * _Nonnull error) {
721
+ CDVPluginResult* pluginResult = nil ;
722
+
723
+ if (!error) {
724
+ NSString * imageString = [qrCodeData base64EncodedStringWithOptions: nil ];
725
+ NSLog (@" Success" );
726
+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString: imageString];
727
+ } else {
728
+ NSLog (@" Error" );
729
+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: [error localizedDescription ]];
730
+ }
731
+
732
+ [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
733
+ }];
734
+ }
735
+
736
+ - (UIColor *) colorWithHexString : (NSString *) hexString {
737
+ NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @" #" withString: @" " ] uppercaseString ];
738
+ CGFloat alpha, red, blue, green;
739
+ switch ([colorString length ]) {
740
+ case 3 : // #RGB
741
+ alpha = 1 .0f ;
742
+ red = [self colorComponentFrom: colorString start: 0 length: 1 ];
743
+ green = [self colorComponentFrom: colorString start: 1 length: 1 ];
744
+ blue = [self colorComponentFrom: colorString start: 2 length: 1 ];
745
+ break ;
746
+ case 4 : // #ARGB
747
+ alpha = [self colorComponentFrom: colorString start: 0 length: 1 ];
748
+ red = [self colorComponentFrom: colorString start: 1 length: 1 ];
749
+ green = [self colorComponentFrom: colorString start: 2 length: 1 ];
750
+ blue = [self colorComponentFrom: colorString start: 3 length: 1 ];
751
+ break ;
752
+ case 6 : // #RRGGBB
753
+ alpha = 1 .0f ;
754
+ red = [self colorComponentFrom: colorString start: 0 length: 2 ];
755
+ green = [self colorComponentFrom: colorString start: 2 length: 2 ];
756
+ blue = [self colorComponentFrom: colorString start: 4 length: 2 ];
757
+ break ;
758
+ case 8 : // #AARRGGBB
759
+ alpha = [self colorComponentFrom: colorString start: 0 length: 2 ];
760
+ red = [self colorComponentFrom: colorString start: 2 length: 2 ];
761
+ green = [self colorComponentFrom: colorString start: 4 length: 2 ];
762
+ blue = [self colorComponentFrom: colorString start: 6 length: 2 ];
763
+ break ;
764
+ default :
765
+ NSLog (@" Error: Invalid color value. It should be a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB" );
766
+ break ;
767
+ }
768
+ return [UIColor colorWithRed: red green: green blue: blue alpha: alpha];
769
+ }
770
+
771
+ - (CGFloat) colorComponentFrom : (NSString *) string start : (NSUInteger ) start length : (NSUInteger ) length {
772
+ NSString *substring = [string substringWithRange: NSMakeRange (start, length)];
773
+ NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @" %@%@ " , substring, substring];
774
+ unsigned hexComponent;
775
+ [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent];
776
+ return hexComponent / 255.0 ;
777
+ }
651
778
652
779
#pragma mark - URL Methods (not fully implemented YET!)
653
780
0 commit comments