diff --git a/CleverPush/Source/CPAppBannerModuleInstance.m b/CleverPush/Source/CPAppBannerModuleInstance.m index 7d66b8ea..eded6bb2 100644 --- a/CleverPush/Source/CPAppBannerModuleInstance.m +++ b/CleverPush/Source/CPAppBannerModuleInstance.m @@ -273,8 +273,8 @@ - (void)getBanners:(NSString*)channelId completion:(void(^)(NSMutableArray*))callback { - if (channelId == nil || ![channelId isKindOfClass:[NSString class]] || [channelId length] == 0) { - [CPLog error:@"Failed getting app banners because channel ID is nil or empty"]; + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: getBanners: channelId is nil or empty, skipping API call"]; return; } @@ -1680,6 +1680,11 @@ - (void)sendBannerEvent:(NSString*)event forBanner:(CPAppBanner*)banner forScree return; } + if ([CPUtils isNullOrEmpty:banner.channel]) { + [CPLog error:@"CleverPush: sendBannerEvent: channelId is nil or empty, skipping API call"]; + return; + } + NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:[NSString stringWithFormat:@"app-banner/event/%@", event]]; NSString* subscriptionId = nil; diff --git a/CleverPush/Source/CPInboxView.m b/CleverPush/Source/CPInboxView.m index 4e8e46e7..f47f4b66 100644 --- a/CleverPush/Source/CPInboxView.m +++ b/CleverPush/Source/CPInboxView.m @@ -432,6 +432,11 @@ - (void)showBanner:(CPAppBanner*)banner force:(BOOL)force { #pragma mark - Get the banner details by api call and load the banner data in to class variables - (void)getBanners:(NSString*)channelId bannerId:(NSString*)bannerId notificationId:(NSString*)notificationId groupId:(NSString*)groupId completion:(void(^)(NSMutableArray*))callback { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: CPInboxView getBanners: channelId is nil or empty, skipping API call"]; + return; + } + NSString* bannersPath = [NSString stringWithFormat:@"channel/%@/app-banners?platformName=iOS", channelId]; if ([CleverPush isDevelopmentModeEnabled]) { @@ -462,7 +467,10 @@ - (void)getBanners:(NSString*)channelId bannerId:(NSString*)bannerId notificatio } - (void)sendBannerEvent:(NSString*)event forBanner:(CPAppBanner*)banner forScreen:(CPAppBannerCarouselBlock*)screen forButtonBlock:(CPAppBannerButtonBlock*)block forImageBlock:(CPAppBannerImageBlock*)image blockType:(NSString*)type { - + if ([CPUtils isNullOrEmpty:banner.channel]) { + [CPLog error:@"CleverPush: CPInboxView sendBannerEvent: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:[NSString stringWithFormat:@"app-banner/event/%@", event]]; diff --git a/CleverPush/Source/CleverPushInstance.m b/CleverPush/Source/CleverPushInstance.m index 52e99b73..332d1f3f 100644 --- a/CleverPush/Source/CleverPushInstance.m +++ b/CleverPush/Source/CleverPushInstance.m @@ -1188,6 +1188,10 @@ - (void)areNotificationsEnabled:(void(^ _Nullable)(BOOL))callback { #pragma mark - channel subscription - (void)setConfirmAlertShown { [self getChannelConfig:^(NSDictionary* channelConfig) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: setConfirmAlertShown: channelId is nil or empty, skipping API call"]; + return; + } confirmAlertShown = YES; NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:[NSString stringWithFormat:@"channel/confirm-alert"]]; @@ -1508,6 +1512,10 @@ - (void)unsubscribe:(void(^ _Nullable)(BOOL))callback onFailure:(CPFailureBlock [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(syncSubscription:) object:nil]; if (subscriptionId) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: unsubscribe: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/unsubscribe"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -1715,6 +1723,12 @@ - (void)makeSyncSubscriptionRequest:(CPFailureBlock)failureBlock successBlock:(v channelId = [self getChannelIdFromUserDefaults]; } + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: makeSyncSubscriptionRequest: channelId is nil or empty, skipping API call"]; + [self setSubscriptionInProgress:false]; + return; + } + NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:[NSString stringWithFormat:@"subscription/sync/%@", channelId]]; [self areNotificationsEnabled:^(BOOL notificationsEnabled) { @@ -2136,6 +2150,10 @@ - (void)setNotificationDelivered:(NSDictionary*)notification { } - (void)setNotificationDelivered:(NSDictionary*)notification withChannelId:(NSString*)channelId withSubscriptionId:(NSString*)subscriptionId { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: setNotificationDelivered: channelId is nil or empty, skipping API call"]; + return; + } NSString*notificationId = [notification valueForKey:@"_id"]; NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"notification/delivered"]; @@ -2191,6 +2209,10 @@ - (void)setNotificationClicked:(NSString*)notificationId { } - (void)setNotificationClicked:(NSString*)notificationId withChannelId:(NSString*)channelId withSubscriptionId:(NSString*)subscriptionId withAction:(NSString*)action { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: setNotificationClicked: channelId is nil or empty, skipping API call"]; + return; + } [CPLog debug:@"setNotificationClicked notification:%@, subscription:%@, channel:%@, action:%@", notificationId, subscriptionId, channelId, action]; NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"notification/clicked"]; @@ -2415,6 +2437,13 @@ - (void)removeSubscriptionTagFromApi:(NSString* _Nullable)tagId callback:(void(^ return; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: removeSubscriptionTagFromApi: channelId is nil or empty, skipping API call"]; + if (callback) { + callback(tagId); + } + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/untag"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2484,6 +2513,10 @@ - (void)removeSubscriptionAttributeFromApi:(NSString* _Nullable)attributeId call return; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: removeSubscriptionAttributeFromApi: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/attribute/clear"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2548,6 +2581,13 @@ - (void)addSubscriptionTagToApi:(NSString* _Nullable)tagId callback:(void(^ _Nul return; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: addSubscriptionTagToApi: channelId is nil or empty, skipping API call"]; + if (callback) { + callback(tagId); + } + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/tag"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2620,6 +2660,10 @@ - (void)removeSubscriptionTagsAndAttributes { - (void)stopCampaigns { if (subscriptionId != nil) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: stopCampaigns: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/stop-campaigns"]; NSMutableDictionary* dataDic = [NSMutableDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2642,6 +2686,10 @@ - (void)startLiveActivity:(NSString* _Nullable)activityId pushToken:(NSString* _ - (void)startLiveActivity:(NSString* _Nullable)activityId pushToken:(NSString* _Nullable)token onSuccess:(CPResultSuccessBlock _Nullable)successBlock onFailure:(CPFailureBlock _Nullable)failureBlock { if (subscriptionId != nil) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: startLiveActivity: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:[NSString stringWithFormat:@"subscription/sync/%@", channelId]]; NSMutableDictionary* dataDic = [NSMutableDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2714,6 +2762,10 @@ - (void)setSubscriptionAttributeObjectImplementation:(NSString*)attributeId obje return; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: setSubscriptionAttributeObjectImplementation: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/attribute"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2766,6 +2818,10 @@ - (void)pushSubscriptionAttributeValue:(NSString* _Nullable)attributeId value:(N } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: pushSubscriptionAttributeValue: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/attribute/push-value"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -2833,6 +2889,10 @@ - (void)pullSubscriptionAttributeValue:(NSString* _Nullable)attributeId value:(N } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: pullSubscriptionAttributeValue: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/attribute/pull-value"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -3103,6 +3163,10 @@ - (void)addSubscriptionTopic:(NSString* _Nullable)topicId callback:(void(^ _Null } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: addSubscriptionTopic: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/topic/add"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -3171,6 +3235,10 @@ - (void)removeSubscriptionTopic:(NSString* _Nullable)topicId callback:(void(^ _N [topics removeObject:topicId]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: removeSubscriptionTopic: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/topic/remove"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -3305,6 +3373,13 @@ - (void)getNotifications:(BOOL)combineWithApi callback:(void(^ _Nullable)(NSArra - (void)getNotifications:(BOOL)combineWithApi limit:(int)limit skip:(int)skip callback:(void(^ _Nullable)(NSArray* _Nullable))callback { NSMutableArray* notifications = [[self getNotifications] mutableCopy]; if (combineWithApi) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: getNotifications: channelId is nil or empty, skipping API call"]; + if (callback) { + callback(notifications); + } + return; + } NSString*combinedURL = [self generateGetReceivedNotificationsPath:limit skip:skip]; [self getReceivedNotificationsFromApi:combinedURL callback:^(NSArray*remoteNotifications) { for (NSDictionary*remoteNotification in remoteNotifications) { @@ -3346,6 +3421,10 @@ - (void)getNotifications:(BOOL)combineWithApi limit:(int)limit skip:(int)skip ca #pragma mark - Track inbox clicked - (void)trackInboxClicked:(NSString* _Nullable)notificationId { if (![CPUtils isNullOrEmpty:notificationId]) { + if ([CPUtils isNullOrEmpty:[CleverPush channelId]]) { + [CPLog error:@"CleverPush: trackInboxClicked: channelId is nil or empty, skipping API call"]; + return; + } NSString* path = [NSString stringWithFormat:@"/channel/%@/panel/clicked", [CleverPush channelId]]; NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:path]; @@ -3496,6 +3575,10 @@ - (void)trackEvent:(NSString* _Nullable)eventName properties:(NSDictionary* _Nul [CPLog debug:@"CleverPushInstance: trackEvent: There is no subscription for CleverPush SDK."]; return; } + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: trackEvent: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/conversion"]; NSMutableDictionary* dataDic = [NSMutableDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -3552,6 +3635,10 @@ - (void)triggerFollowUpEvent:(NSString* _Nullable)eventName parameters:(NSDictio [CPLog debug:@"CleverPushInstance: triggerFollowUpEvent: There is no subscription for CleverPush SDK."]; return; } + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: triggerFollowUpEvent: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/event"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -3895,6 +3982,10 @@ - (void)trackSessionStart { NSUserDefaults* groupUserDefaults = [CPUtils getUserDefaultsAppGroup]; NSString* lastNotificationId = [groupUserDefaults stringForKey:CLEVERPUSH_LAST_NOTIFICATION_ID_KEY]; + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: trackSessionStart: channelId is nil or empty, skipping API call"]; + return; + } NSMutableURLRequest* request = [[CleverPushHTTPClient sharedClient] requestWithMethod:HTTP_POST path:@"subscription/session/start"]; NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys: channelId, @"channelId", @@ -3960,7 +4051,10 @@ - (void)trackSessionEnd { long sessionDuration = sessionEndedTimestamp - sessionStartedTimestamp; long visits = MAX(sessionVisits, 0); - if (channelId == nil || subscriptionId == nil || deviceToken == nil || sessionDuration < 0) { + if ([CPUtils isNullOrEmpty:channelId] || subscriptionId == nil || deviceToken == nil || sessionDuration < 0) { + if ([CPUtils isNullOrEmpty:channelId]) { + [CPLog error:@"CleverPush: trackSessionEnd: channelId is nil or empty, skipping API call"]; + } return; }