Showing
5 changed files
with
175 additions
and
12 deletions
| ... | @@ -101,7 +101,8 @@ | ... | @@ -101,7 +101,8 @@ |
| 101 | - (void)getMultilingualMerchantsAsync:(NSArray*)categories andDefaultShown:(NSNumber*)defaultShown andCenter:(NSNumber*)center andTags:(NSArray*)tags andUuid:(NSString*)uuid andDistance:(NSNumber*)distance parent_uuids:(NSArray*)parent_uuids :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; | 101 | - (void)getMultilingualMerchantsAsync:(NSArray*)categories andDefaultShown:(NSNumber*)defaultShown andCenter:(NSNumber*)center andTags:(NSArray*)tags andUuid:(NSString*)uuid andDistance:(NSNumber*)distance parent_uuids:(NSArray*)parent_uuids :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; |
| 102 | // - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; | 102 | // - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; |
| 103 | - (void)didReceiveNotification:(NSDictionary *)payload; | 103 | - (void)didReceiveNotification:(NSDictionary *)payload; |
| 104 | -- (NSNumber*)checkforLoyaltySDKNotification:(NSDictionary *)payload; | 104 | +- (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload; |
| 105 | +//- (NSNumber*)checkforLoyaltySDKNotification:(NSDictionary *)payload; | ||
| 105 | // TEST CODE FOR PUSH | 106 | // TEST CODE FOR PUSH |
| 106 | // - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload whileAppWasInState:(UIApplicationState)appState; | 107 | // - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload whileAppWasInState:(UIApplicationState)appState; |
| 107 | // TEST CODE FOR PUSH | 108 | // TEST CODE FOR PUSH | ... | ... |
| ... | @@ -1693,17 +1693,28 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1693,17 +1693,28 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
| 1693 | - (void)didReceiveNotification:(NSDictionary *)payload { | 1693 | - (void)didReceiveNotification:(NSDictionary *)payload { |
| 1694 | 1694 | ||
| 1695 | if ([Warply sharedServiceExists] == YES) { | 1695 | if ([Warply sharedServiceExists] == YES) { |
| 1696 | - [[Warply sharedService].pushManager didReceiveRemoteNotification:payload whileAppWasInState:WLApplicationStateClosed]; | 1696 | +// [[Warply sharedService].pushManager didReceiveRemoteNotification:payload whileAppWasInState:WLApplicationStateClosed]; |
| 1697 | + [[Warply sharedService].pushManager didReceiveNotificationPM:payload]; | ||
| 1697 | } | 1698 | } |
| 1698 | } | 1699 | } |
| 1699 | 1700 | ||
| 1700 | // - (BOOL)checkForLoyaltySDKNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state { | 1701 | // - (BOOL)checkForLoyaltySDKNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state { |
| 1701 | -- (NSNumber*)checkforLoyaltySDKNotification:(NSDictionary *)payload { | 1702 | +//- (NSNumber*)checkforLoyaltySDKNotification:(NSDictionary *)payload { |
| 1703 | +// | ||
| 1704 | +// if ([Warply sharedServiceExists] == YES) { | ||
| 1705 | +// return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload] ? @1 : @0; | ||
| 1706 | +// } else { | ||
| 1707 | +// return nil; | ||
| 1708 | +// } | ||
| 1709 | +//} | ||
| 1710 | + | ||
| 1711 | +- (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload { | ||
| 1702 | 1712 | ||
| 1703 | - if ([Warply sharedServiceExists] == YES) { | 1713 | + if ([payload valueForKey:@"_a"] == nil) { |
| 1704 | - return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload] ? @1 : @0; | 1714 | + // The push was sent from another push service |
| 1715 | + return NO; | ||
| 1705 | } else { | 1716 | } else { |
| 1706 | - return nil; | 1717 | + return YES; |
| 1707 | } | 1718 | } |
| 1708 | } | 1719 | } |
| 1709 | 1720 | ... | ... |
| ... | @@ -161,6 +161,8 @@ typedef enum WLApplicationState : unsigned int{ | ... | @@ -161,6 +161,8 @@ typedef enum WLApplicationState : unsigned int{ |
| 161 | */ | 161 | */ |
| 162 | - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; | 162 | - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; |
| 163 | 163 | ||
| 164 | +- (void)didReceiveNotificationPM:(NSDictionary *)userInfo; | ||
| 165 | + | ||
| 164 | - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo; | 166 | - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo; |
| 165 | // TEST CODE FOR PUSH | 167 | // TEST CODE FOR PUSH |
| 166 | // - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo whileAppWasInState:(UIApplicationState)appState; | 168 | // - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo whileAppWasInState:(UIApplicationState)appState; | ... | ... |
| ... | @@ -303,6 +303,90 @@ static const char* jailbreak_apps[] = | ... | @@ -303,6 +303,90 @@ static const char* jailbreak_apps[] = |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | /////////////////////////////////////////////////////////////////////////////// | 305 | /////////////////////////////////////////////////////////////////////////////// |
| 306 | +//- (BOOL)didReceiveNotificationPM:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state | ||
| 307 | +- (void)didReceiveNotificationPM:(NSDictionary *)userInfo | ||
| 308 | +{ | ||
| 309 | + // TODO: Check if this guard should be commented | ||
| 310 | + if ([userInfo valueForKey:@"_a"] == nil) { | ||
| 311 | + // The push was sent from another push service | ||
| 312 | + return; | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + // TODO: Check if states are correct, especially from didFinishLaunchingWithOptions | ||
| 316 | + WLApplicationState state; | ||
| 317 | + if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) | ||
| 318 | + state = WLApplicationStateActive; | ||
| 319 | + else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) | ||
| 320 | + state = WLApplicationStateClosed; | ||
| 321 | + else | ||
| 322 | + state = WLApplicationStateBackground; | ||
| 323 | + | ||
| 324 | + | ||
| 325 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:NSJSONWritingPrettyPrinted error:nil]; | ||
| 326 | + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | ||
| 327 | + WLLOG(@"Did receive push: %@", jsonString); | ||
| 328 | + WLInboxItem *inboxItem = [[WLInboxItem alloc] initWithAttributes:userInfo] ; | ||
| 329 | +// [WLAnalyticsManager logUserReceivedPush:inboxItem]; | ||
| 330 | + | ||
| 331 | + if (state != WLApplicationStateActive) { | ||
| 332 | + [WLAnalyticsManager logUserEngagedPush:inboxItem]; | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + if (inboxItem.action != 0) { | ||
| 336 | + [self.customPushHanlder didReceiveRemoteNotification:userInfo whileAppWasInState:state]; | ||
| 337 | + return; | ||
| 338 | + } | ||
| 339 | + switch (state) { | ||
| 340 | + case WLApplicationStateActive: | ||
| 341 | + { | ||
| 342 | + UIAlertController * alert = [UIAlertController alertControllerWithTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] message:@"" preferredStyle:UIAlertControllerStyleAlert]; | ||
| 343 | + | ||
| 344 | + UIAlertAction* yesButton = [UIAlertAction | ||
| 345 | + actionWithTitle:NSLocalizedString(@"Close", @"Warply") | ||
| 346 | + style:UIAlertActionStyleDefault | ||
| 347 | + handler:^(UIAlertAction * action) { | ||
| 348 | + //Handle your yes please button action here | ||
| 349 | + }]; | ||
| 350 | + | ||
| 351 | + UIAlertAction* noButton = [UIAlertAction | ||
| 352 | + actionWithTitle:NSLocalizedString(@"View", @"Warply") | ||
| 353 | + style:UIAlertActionStyleDefault | ||
| 354 | + handler:^(UIAlertAction * action) { | ||
| 355 | + //Handle no, thanks button | ||
| 356 | + }]; | ||
| 357 | + | ||
| 358 | + [alert addAction:yesButton]; | ||
| 359 | + [alert addAction:noButton]; | ||
| 360 | + | ||
| 361 | + UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | ||
| 362 | + alertWindow.rootViewController = [[UIViewController alloc] init]; | ||
| 363 | + alertWindow.windowLevel = UIWindowLevelAlert + 1; | ||
| 364 | + [alertWindow makeKeyAndVisible]; | ||
| 365 | + [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil]; | ||
| 366 | + | ||
| 367 | + // UIAlertView *alert = [[UIAlertView alloc] init]; | ||
| 368 | + // [alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]; | ||
| 369 | + // [alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")]; | ||
| 370 | + // [alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")]; | ||
| 371 | + // [alert setDelegate:self]; | ||
| 372 | + // [alert show]; | ||
| 373 | + | ||
| 374 | + self.pendingItem = inboxItem; | ||
| 375 | + break; | ||
| 376 | + } | ||
| 377 | + case WLApplicationStateBackground: | ||
| 378 | + { | ||
| 379 | + [self showItem:inboxItem]; | ||
| 380 | + break; | ||
| 381 | + } | ||
| 382 | + case WLApplicationStateClosed: | ||
| 383 | + self.pendingItem = inboxItem; | ||
| 384 | + break; | ||
| 385 | + } | ||
| 386 | + return; | ||
| 387 | +} | ||
| 388 | + | ||
| 389 | +/////////////////////////////////////////////////////////////////////////////// | ||
| 306 | //- (BOOL)checkForLoyaltySDKNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state | 390 | //- (BOOL)checkForLoyaltySDKNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state |
| 307 | - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo | 391 | - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo |
| 308 | { | 392 | { | ... | ... |
| ... | @@ -80,6 +80,22 @@ public class swiftApi { | ... | @@ -80,6 +80,22 @@ public class swiftApi { |
| 80 | UserDefaults.standard.set(newValue, forKey: "trackersEnabled") | 80 | UserDefaults.standard.set(newValue, forKey: "trackersEnabled") |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | + public func getAppUuid() -> String { | ||
| 84 | + return UserDefaults.standard.string(forKey: "appUuidUD") ?? "" | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public func setAppUuid(_ newUserTag: String) -> Void { | ||
| 88 | + UserDefaults.standard.set(newUserTag, forKey: "appUuidUD") | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public func getMerchantId() -> String { | ||
| 92 | + return UserDefaults.standard.string(forKey: "merchantIdUD") ?? "" | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public func setMerchantId(_ newUserTag: String) -> Void { | ||
| 96 | + UserDefaults.standard.set(newUserTag, forKey: "merchantIdUD") | ||
| 97 | + } | ||
| 98 | + | ||
| 83 | public func getStepsWebview() -> Int { | 99 | public func getStepsWebview() -> Int { |
| 84 | return GlobalVariables.stepsWebview | 100 | return GlobalVariables.stepsWebview |
| 85 | } | 101 | } |
| ... | @@ -6189,17 +6205,48 @@ public class swiftApi { | ... | @@ -6189,17 +6205,48 @@ public class swiftApi { |
| 6189 | public func didReceiveNotification(_ payload: [String : Any]) -> Void { | 6205 | public func didReceiveNotification(_ payload: [String : Any]) -> Void { |
| 6190 | 6206 | ||
| 6191 | let instanceOfMyApi = MyApi() | 6207 | let instanceOfMyApi = MyApi() |
| 6192 | - instanceOfMyApi.didReceiveNotification(payload) | 6208 | + let isInitialised = instanceOfMyApi.sdkInitialised(); |
| 6209 | + | ||
| 6210 | + if (isInitialised == true) { | ||
| 6211 | + instanceOfMyApi.didReceiveNotification(payload) | ||
| 6212 | + } else { | ||
| 6213 | + let appUuid = swiftApi().getAppUuid() | ||
| 6214 | + let merchantId = swiftApi().getMerchantId() | ||
| 6215 | + instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback) | ||
| 6216 | + } | ||
| 6217 | + | ||
| 6218 | + func initializeCallback(_ initializeData: [AnyHashable: Any]?) -> Void { | ||
| 6219 | + if ((initializeData?["status"] as? Int) == 1) { | ||
| 6220 | + instanceOfMyApi.didReceiveNotification(payload) | ||
| 6221 | + } | ||
| 6222 | + } | ||
| 6223 | + | ||
| 6224 | + func initializeFailureCallback(_ error: Error?) -> Void { | ||
| 6225 | + } | ||
| 6193 | } | 6226 | } |
| 6194 | - | 6227 | + |
| 6195 | - | 6228 | + |
| 6196 | - public func checkForLoyaltySDKNotification(_ payload: [String : Any]) -> Bool? { | 6229 | + public func checkForLoyaltySDKNotification(_ payload: [String : Any]) -> Bool { |
| 6197 | 6230 | ||
| 6198 | let instanceOfMyApi = MyApi() | 6231 | let instanceOfMyApi = MyApi() |
| 6199 | - return instanceOfMyApi.checkforLoyaltySDKNotification(payload) as? Bool | 6232 | + let isSDKPush = instanceOfMyApi.checkforLoyaltySDKNotification(payload) |
| 6233 | + | ||
| 6234 | + if (isSDKPush == false) { | ||
| 6235 | + return false; | ||
| 6236 | + } else { | ||
| 6237 | + swiftApi().didReceiveNotification(payload) | ||
| 6238 | + return true; | ||
| 6239 | + } | ||
| 6200 | } | 6240 | } |
| 6201 | 6241 | ||
| 6202 | 6242 | ||
| 6243 | + // public func checkForLoyaltySDKNotification(_ payload: [String : Any]) -> Bool? { | ||
| 6244 | + | ||
| 6245 | + // let instanceOfMyApi = MyApi() | ||
| 6246 | + // return instanceOfMyApi.checkforLoyaltySDKNotification(payload) as? Bool | ||
| 6247 | + // } | ||
| 6248 | + | ||
| 6249 | + | ||
| 6203 | // TEST CODE FOR PUSH | 6250 | // TEST CODE FOR PUSH |
| 6204 | // public func checkForLoyaltySDKNotification(_ payload: [String : Any], _ appState: UIApplication.State) -> Bool { | 6251 | // public func checkForLoyaltySDKNotification(_ payload: [String : Any], _ appState: UIApplication.State) -> Bool { |
| 6205 | 6252 | ||
| ... | @@ -6266,7 +6313,9 @@ public class swiftApi { | ... | @@ -6266,7 +6313,9 @@ public class swiftApi { |
| 6266 | if (isInitialised == true) { | 6313 | if (isInitialised == true) { |
| 6267 | instanceOfMyApi.sendDeviceInfoIfNecessary(newDeviceToken) | 6314 | instanceOfMyApi.sendDeviceInfoIfNecessary(newDeviceToken) |
| 6268 | } else { | 6315 | } else { |
| 6269 | - instanceOfMyApi.initialize(withCallback: nil, uuid: "0086a2088301440792091b9f814c2267", merchantId: "58763", lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback) | 6316 | + let appUuid = swiftApi().getAppUuid() |
| 6317 | + let merchantId = swiftApi().getMerchantId() | ||
| 6318 | + instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback) | ||
| 6270 | } | 6319 | } |
| 6271 | 6320 | ||
| 6272 | 6321 | ||
| ... | @@ -6454,4 +6503,20 @@ public class swiftApi { | ... | @@ -6454,4 +6503,20 @@ public class swiftApi { |
| 6454 | } | 6503 | } |
| 6455 | 6504 | ||
| 6456 | 6505 | ||
| 6506 | + public func getIsDevEnvironment(_ isDevEnv: Bool) -> Void { | ||
| 6507 | + // PROD app: 0086a2088301440792091b9f814c2267 | ||
| 6508 | + // DEV app: f83dfde1145e4c2da69793abb2f579af | ||
| 6509 | + // PROD merchantId: 58763 | ||
| 6510 | + // DEV merchantId: 20113 | ||
| 6511 | + | ||
| 6512 | + if (isDevEnv == true) { | ||
| 6513 | + swiftApi().setAppUuid("f83dfde1145e4c2da69793abb2f579af") | ||
| 6514 | + swiftApi().setMerchantId("20113") | ||
| 6515 | + } else { | ||
| 6516 | + swiftApi().setAppUuid("0086a2088301440792091b9f814c2267") | ||
| 6517 | + swiftApi().setMerchantId("58763") | ||
| 6518 | + } | ||
| 6519 | + } | ||
| 6520 | + | ||
| 6521 | + | ||
| 6457 | } | 6522 | } | ... | ... |
-
Please register or login to post a comment