Merge branch 'master' of https://git.warp.ly/open-source/warply_sdk_framework
Showing
7 changed files
with
157 additions
and
54 deletions
No preview for this file type
| ... | @@ -285,6 +285,9 @@ WL_VERSION_INTERFACE() | ... | @@ -285,6 +285,9 @@ WL_VERSION_INTERFACE() |
| 285 | - (BOOL)getInboxWithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | 285 | - (BOOL)getInboxWithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; |
| 286 | 286 | ||
| 287 | 287 | ||
| 288 | +- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | ||
| 289 | + | ||
| 290 | + | ||
| 288 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure; | 291 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure; |
| 289 | 292 | ||
| 290 | - (void)sendContactWithSuccessBlock:(NSString *)name andEmail:(NSString *)email andMsisdn:msisdn andMessage:message :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure; | 293 | - (void)sendContactWithSuccessBlock:(NSString *)name andEmail:(NSString *)email andMsisdn:msisdn andMessage:message :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
| ... | @@ -430,6 +430,30 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -430,6 +430,30 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 430 | return [self isRegistrationValid]; | 430 | return [self isRegistrationValid]; |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | +- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure | ||
| 434 | +{ | ||
| 435 | + if (self.allOffers.count > 0) { | ||
| 436 | + success(self.allOffers); | ||
| 437 | + } else { | ||
| 438 | + NSDictionary *postDictionary = @{@"offers": @{@"action": @"get_inbox"}}; | ||
| 439 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
| 440 | + | ||
| 441 | + [self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 442 | + if (success) { | ||
| 443 | + success([contextResponse valueForKey:@"MAPP_OFFER"]); | ||
| 444 | + } | ||
| 445 | + } failureBlock:^(NSError *error) { | ||
| 446 | + if (failure) { | ||
| 447 | + failure(error); | ||
| 448 | + } | ||
| 449 | + }]; | ||
| 450 | + } | ||
| 451 | + | ||
| 452 | + | ||
| 453 | + return [self isRegistrationValid]; | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | + | ||
| 433 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure | 457 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure |
| 434 | { | 458 | { |
| 435 | if (filter == nil) { | 459 | if (filter == nil) { | ... | ... |
No preview for this file type
| ... | @@ -3,22 +3,4 @@ | ... | @@ -3,22 +3,4 @@ |
| 3 | uuid = "91478161-56E8-4654-93F2-7756A39480EE" | 3 | uuid = "91478161-56E8-4654-93F2-7756A39480EE" |
| 4 | type = "0" | 4 | type = "0" |
| 5 | version = "2.0"> | 5 | version = "2.0"> |
| 6 | - <Breakpoints> | ||
| 7 | - <BreakpointProxy | ||
| 8 | - BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | ||
| 9 | - <BreakpointContent | ||
| 10 | - uuid = "28AEA58D-19E0-4D42-BABE-9F1C341D6182" | ||
| 11 | - shouldBeEnabled = "Yes" | ||
| 12 | - ignoreCount = "0" | ||
| 13 | - continueAfterRunningActions = "No" | ||
| 14 | - filePath = "WarplySDKFrameworkIOS/CouponsView.swift" | ||
| 15 | - startingColumnNumber = "9223372036854775807" | ||
| 16 | - endingColumnNumber = "9223372036854775807" | ||
| 17 | - startingLineNumber = "100" | ||
| 18 | - endingLineNumber = "100" | ||
| 19 | - landmarkName = "previews" | ||
| 20 | - landmarkType = "24"> | ||
| 21 | - </BreakpointContent> | ||
| 22 | - </BreakpointProxy> | ||
| 23 | - </Breakpoints> | ||
| 24 | </Bucket> | 6 | </Bucket> | ... | ... |
| ... | @@ -9,36 +9,114 @@ | ... | @@ -9,36 +9,114 @@ |
| 9 | import SwiftUI | 9 | import SwiftUI |
| 10 | 10 | ||
| 11 | class DataModel { | 11 | class DataModel { |
| 12 | - var data: Array<NSDictionary>? | 12 | + var data: Array<NSDictionary> = [] |
| 13 | 13 | ||
| 14 | init() { //initializer method | 14 | init() { //initializer method |
| 15 | let instanceOfMyApi = MyApi() | 15 | let instanceOfMyApi = MyApi() |
| 16 | let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) | 16 | let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) |
| 17 | let coupons = instanceOfMyApi.getCoupons() as AnyObject? | 17 | let coupons = instanceOfMyApi.getCoupons() as AnyObject? |
| 18 | 18 | ||
| 19 | + if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | ||
| 20 | + let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) | ||
| 21 | + if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
| 22 | + let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>) | ||
| 23 | + if let sets = couponSetsData as? NSArray { | ||
| 24 | + for set in sets { | ||
| 25 | + let s = set as! NSDictionary | ||
| 26 | + if let cpns = couponsData as? NSArray { | ||
| 27 | + for coupon in cpns { | ||
| 28 | + var c = coupon as! NSDictionary | ||
| 29 | +// var temp = NSMutableDictionary(dictionary: s); | ||
| 30 | + if c["couponset_uuid"] as! String == s["uuid"] as! String { | ||
| 31 | + var temp = NSMutableDictionary(dictionary: s); | ||
| 32 | + temp.addEntries(from: c as! [AnyHashable : Any]) | ||
| 33 | + | ||
| 34 | + self.data.append(temp as NSDictionary) | ||
| 35 | + } | ||
| 19 | 36 | ||
| 20 | - if let myDictionary = coupons as? [String : AnyObject] { | 37 | + } |
| 21 | - self.data = (myDictionary["result"] as! Array<NSDictionary>) | 38 | + } |
| 39 | + | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + } | ||
| 22 | } | 43 | } |
| 23 | } | 44 | } |
| 24 | 45 | ||
| 25 | var getData: Array<NSDictionary> { | 46 | var getData: Array<NSDictionary> { |
| 26 | get { // getter | 47 | get { // getter |
| 27 | - return data ?? [] | 48 | + return data |
| 28 | } | 49 | } |
| 29 | } | 50 | } |
| 30 | } | 51 | } |
| 31 | 52 | ||
| 53 | +struct UrlImageView: View { | ||
| 54 | + @ObservedObject var urlImageModel: UrlImageModel | ||
| 32 | 55 | ||
| 33 | -@available(iOS 13.0.0, *) | 56 | + init(urlString: String?) { |
| 34 | -struct CouponsView: View { | 57 | + urlImageModel = UrlImageModel(urlString: urlString) |
| 58 | + } | ||
| 35 | 59 | ||
| 36 | - var data:Array<NSDictionary> = DataModel().getData | 60 | + var body: some View { |
| 61 | + Image(uiImage: urlImageModel.image ?? UrlImageView.defaultImage!) | ||
| 62 | + .resizable() | ||
| 63 | + .scaledToFill() | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + static var defaultImage = UIImage(systemName: "photo") | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +class UrlImageModel: ObservableObject { | ||
| 70 | + @Published var image: UIImage? | ||
| 71 | + var urlString: String? | ||
| 72 | + | ||
| 73 | + init(urlString: String?) { | ||
| 74 | + self.urlString = urlString | ||
| 75 | + loadImage() | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + func loadImage() { | ||
| 79 | + loadImageFromUrl() | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + func loadImageFromUrl() { | ||
| 83 | + guard let urlString = urlString else { | ||
| 84 | + return | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + let url = URL(string: urlString)! | ||
| 88 | + let task = URLSession.shared.dataTask(with: url, completionHandler: | ||
| 89 | + getImageFromResponse(data:response:error:)) | ||
| 90 | + task.resume() | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + | ||
| 94 | + func getImageFromResponse(data: Data?, response: URLResponse?, error: Error?) | ||
| 95 | + { | ||
| 96 | + guard error == nil else { | ||
| 97 | + print("Error: \(error!)") | ||
| 98 | + return | ||
| 99 | + } | ||
| 100 | + guard let data = data else { | ||
| 101 | + print("No data found") | ||
| 102 | + return | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + DispatchQueue.main.async { | ||
| 106 | + guard let loadedImage = UIImage(data: data) else { | ||
| 107 | + return | ||
| 108 | + } | ||
| 109 | + self.image = loadedImage | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +extension CouponsView { | ||
| 115 | + struct headerView: View { | ||
| 37 | 116 | ||
| 38 | var uiscreen = UIScreen.main.bounds | 117 | var uiscreen = UIScreen.main.bounds |
| 39 | -// @State private var bottomRect: CGRect = .zero | 118 | + |
| 40 | var body: some View { | 119 | var body: some View { |
| 41 | - VStack { | ||
| 42 | ZStack { | 120 | ZStack { |
| 43 | Image("ic_back", bundle: Bundle(for: MyEmptyClass.self)) | 121 | Image("ic_back", bundle: Bundle(for: MyEmptyClass.self)) |
| 44 | .resizable() | 122 | .resizable() |
| ... | @@ -49,41 +127,57 @@ struct CouponsView: View { | ... | @@ -49,41 +127,57 @@ struct CouponsView: View { |
| 49 | .offset( y: self.uiscreen.height * 0.07) | 127 | .offset( y: self.uiscreen.height * 0.07) |
| 50 | .frame(width: self.uiscreen.width) | 128 | .frame(width: self.uiscreen.width) |
| 51 | } | 129 | } |
| 52 | - ScrollView { | 130 | + } |
| 53 | - VStack { | 131 | + } |
| 54 | 132 | ||
| 55 | 133 | ||
| 56 | -// let dataArray:[NSDictionary] = (data as! NSArray).compactMap({ $0 as? NSDictionary }) | ||
| 57 | 134 | ||
| 58 | -// if (data?.count())! > 0 { | 135 | + struct couponView: View { |
| 59 | -// data?.forEach { (language) in | 136 | + var result: NSDictionary |
| 60 | -// ForEach(data, id: \.self) { result in | 137 | + var index: Int |
| 61 | -// | 138 | + |
| 62 | -// | 139 | + var uiscreen = UIScreen.main.bounds |
| 63 | -// | 140 | + |
| 64 | -// ZStack { | 141 | + var body: some View { |
| 65 | -// Image("logo", bundle: Bundle(for: MyEmptyClass.self)) | 142 | + ZStack { |
| 66 | -// .resizable() | 143 | + UrlImageView(urlString: result["img_preview"] as? String) |
| 67 | -// .frame(width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04, alignment: .topLeading) | 144 | + .frame(width: self.uiscreen.height * 0.25, height: self.uiscreen.height * 0.05, alignment: .leading) |
| 68 | -// .cornerRadius(CGFloat(self.uiscreen.height * 0.02)) | 145 | + .offset(x: self.uiscreen.width * 0.05, y: self.uiscreen.height * 0.06) |
| 69 | -// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.14, y: -self.uiscreen.height * 0.07) | 146 | + |
| 70 | -// | ||
| 71 | -// }.background( | ||
| 72 | -// Image("coupons_container", bundle: Bundle(identifier:"framework.warp.ly.warplySDKFrameworkIOS")) | ||
| 73 | -// .resizable() | ||
| 74 | -// .edgesIgnoringSafeArea(.all) | ||
| 75 | -// .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) | ||
| 76 | -// ) | ||
| 77 | -// | ||
| 78 | } | 147 | } |
| 79 | -// | 148 | + .background( |
| 149 | + Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self)) | ||
| 150 | + .resizable() | ||
| 151 | + .offset(x: self.uiscreen.width * 0.05, y: (CGFloat(index + 1) * self.uiscreen.height * 0.06) + CGFloat(index) * self.uiscreen.height * 0.17) | ||
| 152 | + .padding() | ||
| 153 | + .frame(width: UIScreen.main.bounds.width * 0.9, height: UIScreen.main.bounds.height * 0.17, alignment: .topLeading) | ||
| 154 | + ) | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | +} | ||
| 80 | 159 | ||
| 160 | +@available(iOS 13.0.0, *) | ||
| 161 | +struct CouponsView: View { | ||
| 162 | + | ||
| 163 | + var data:Array<NSDictionary> = DataModel().getData | ||
| 164 | + | ||
| 165 | + var uiscreen = UIScreen.main.bounds | ||
| 81 | 166 | ||
| 167 | + var body: some View { | ||
| 168 | + VStack { | ||
| 169 | + headerView() | ||
| 170 | + ScrollView { | ||
| 171 | + VStack { | ||
| 172 | + if (data.count) > 0 { | ||
| 173 | + ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in | ||
| 174 | + couponView(result: result, index: index) | ||
| 175 | + } | ||
| 176 | + } | ||
| 82 | } | 177 | } |
| 83 | .frame(width:self.uiscreen.width, height:self.uiscreen.height ) | 178 | .frame(width:self.uiscreen.width, height:self.uiscreen.height ) |
| 84 | - | ||
| 85 | } | 179 | } |
| 86 | - | 180 | + } |
| 87 | } | 181 | } |
| 88 | } | 182 | } |
| 89 | #endif | 183 | #endif | ... | ... |
| ... | @@ -126,7 +126,7 @@ NSString *LANG; | ... | @@ -126,7 +126,7 @@ NSString *LANG; |
| 126 | __block NSArray *in = [NSMutableArray alloc]; | 126 | __block NSArray *in = [NSMutableArray alloc]; |
| 127 | __block BOOL isRunLoopNested = NO; | 127 | __block BOOL isRunLoopNested = NO; |
| 128 | __block BOOL isOperationCompleted = NO; | 128 | __block BOOL isOperationCompleted = NO; |
| 129 | - [[Warply sharedService] getInboxWithSuccessBlock :^(NSArray *inbox) { | 129 | + [[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) { |
| 130 | in = inbox; | 130 | in = inbox; |
| 131 | isOperationCompleted = YES; | 131 | isOperationCompleted = YES; |
| 132 | if (isRunLoopNested) { | 132 | if (isRunLoopNested) { | ... | ... |
-
Please register or login to post a comment