Skip to content

Commit

Permalink
Merge pull request #240 from blueshift-labs/development
Browse files Browse the repository at this point in the history
Development - v2.2.5
  • Loading branch information
ketanshikharebsft authored Jun 14, 2022
2 parents 48e706f + 1a5df71 commit a0ecb1b
Show file tree
Hide file tree
Showing 33 changed files with 332 additions and 510 deletions.
2 changes: 1 addition & 1 deletion BlueShift-iOS-Extension-SDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "BlueShift-iOS-Extension-SDK"
s.version = "2.2.4"
s.version = "2.2.5"
s.summary = "iOS SDK for Push Notification Service Extension and Content Extension to support image and carousel image push notifications"
s.homepage = "https://github.com/blueshift-labs/Blueshift-iOS-SDK"
s.license = { :type => "MIT", :file => "LICENSE.md" }
Expand Down
17 changes: 0 additions & 17 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushAnalytics.h

This file was deleted.

136 changes: 0 additions & 136 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushAnalytics.m

This file was deleted.

38 changes: 32 additions & 6 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,43 @@
#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(ios(10.0))
@interface BlueShiftPushNotification : NSObject

@property NSArray <UNNotificationAttachment *>* attachments;
@property NSString *apiKey;
@property NSString* appGroupId;
@property NSArray <UNNotificationAttachment *>* _Nullable attachments;

/// The Blueshift iOS Extension SDK will no longer send the `delivered` event for push notifications, so there is no need of setting the API key.
/// Blueshift will now provide the push delivery stats based on the APNS's response.
/// This variable is deprecated and will be removed in the future release.
@property NSString *apiKey DEPRECATED_MSG_ATTRIBUTE("Extension SDK no longer requires the API key and this variable will be removed in the future SDK release.");

/// The SDK will no longer use the app group id for firing the push `delivered` event, so there is no need of setting appGroupId value.
/// Blueshift will now provide the push delivery stats based on the APNS's response.
/// This variable is deprecated and will be removed in the future release.
@property NSString* appGroupId DEPRECATED_MSG_ATTRIBUTE("This variable is deprecated and will be removed in the future SDK release.");

+ (instancetype _Nullable) sharedInstance;

+ (instancetype) sharedInstance;
- (NSArray *)integratePushNotificationWithMediaAttachementsForRequest:(UNNotificationRequest *)request andAppGroupID:(NSString *)appGroupID;
/// Download the media for rendering the Rich push notificaiton.
/// @param request UNNotificationRequest
/// @param appGroupID This method no longer uses the appGroupId value, this parameter is marked as deprecated
/// and will be removed from the method definition in the future SDK release. You may pass `nil` as value for this param.
- (NSArray *)integratePushNotificationWithMediaAttachementsForRequest:(UNNotificationRequest *)request andAppGroupID:(NSString * _Nullable)appGroupID;

/// Check if the push notification is from Blueshift.
/// @param request push notification request.
/// @returns true or false based on if push notification is from Blueshift or not.
- (BOOL)isBlueShiftPushNotification:(UNNotificationRequest *)request;

- (BOOL)hasBlueShiftAttachments;
- (void)trackPushViewedWithRequest:(UNNotificationRequest *)request;

/// The Blueshift iOS Extension SDK will no longer send the `delivered` event for push notifications.
/// Blueshift will now provide the push delivery stats based on the APNS's response.
/// This method is deprecated and will be removed in the future release.
- (void)trackPushViewedWithRequest:(UNNotificationRequest *)request DEPRECATED_MSG_ATTRIBUTE("This method is deprecated as Blueshift iOS Extension SDK will no longer send the `delivered` event for push notifications and will be removed in the future SDK release.");

@end

NS_ASSUME_NONNULL_END
23 changes: 5 additions & 18 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@


#import "BlueShiftPushNotification.h"
#import "BlueShiftPushAnalytics.h"
#import "BlueshiftExtensionAnalyticsHelper.h"
#import "BlueshiftExtensionConstants.h"

API_AVAILABLE(ios(10.0))
Expand Down Expand Up @@ -40,16 +38,7 @@ - (BOOL)hasBlueShiftAttachments {
}
}

- (NSArray *)integratePushNotificationWithMediaAttachementsForRequest:(UNNotificationRequest *)request andAppGroupID:(NSString *)appGroupID {
self.appGroupId = appGroupID;
if (![[BlueShiftPushNotification sharedInstance] apiKey] || [[BlueShiftPushNotification sharedInstance].apiKey isEqualToString:@""]) {
NSLog(@"[Blueshift] Error - Please set the api key in the Notification Service Extension, otherwise push notification delivered events will not reflect on the dashboard");
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self trackPushViewedWithRequest:request];
});

- (NSArray *)integratePushNotificationWithMediaAttachementsForRequest:(UNNotificationRequest *)request andAppGroupID:(NSString * _Nullable)appGroupID {
if ([request.content.categoryIdentifier isEqualToString: kNotificationCarouselIdentifier] || [request.content.categoryIdentifier isEqualToString: kNotificationCarouselAnimationIdentifier]) {
return [self carouselAttachmentsDownload:request];
} else {
Expand All @@ -59,10 +48,6 @@ - (NSArray *)integratePushNotificationWithMediaAttachementsForRequest:(UNNotific
}

- (void)trackPushViewedWithRequest:(UNNotificationRequest *)request {
NSDictionary *userInfo = request.content.userInfo;
if(userInfo && [[BlueShiftPushNotification sharedInstance] apiKey] && ![[[BlueShiftPushNotification sharedInstance] apiKey] isEqualToString:@""]) {
[BlueShiftPushAnalytics sendPushAnalytics:kNotificationDeliveredEvent withParams:userInfo];
}
}

- (NSArray *)carouselAttachmentsDownload:(UNNotificationRequest *)request {
Expand Down Expand Up @@ -202,6 +187,7 @@ - (NSArray *)mediaAttachmentDownlaod:(UNNotificationRequest *)request {
}
}
}
self.attachments = attachments;
return attachments;
}

Expand All @@ -212,7 +198,8 @@ - (void)addNotificationCategory:(UNNotificationRequest *)request{
NSString* pushCategory = aps[kNotificationCategory];
NSString* forceReplaceCategory = userInfo[kNotificationForceReplaceCategory];
NSArray* actionsArray = userInfo[kNotificationActions];
if(actionsArray && pushCategory) {

if(actionsArray && actionsArray.count > 0 && pushCategory) {
__block bool isCategoryRegistrationComplteted = NO;
NSMutableArray<UNNotificationAction *>* notificationActions = [self getNotificationActions:actionsArray];
if (notificationActions.count > 0) {
Expand Down Expand Up @@ -257,7 +244,7 @@ - (NSMutableArray*)getNotificationActions:(NSArray*)actions {
if (actionType && ![actionType isEqualToString:kNotificationActionTypeOpen]) {
if([actionType isEqualToString:kNotificationActionTypeDestructive])
actionOption = UNNotificationActionOptionDestructive;
else if([actionType isEqualToString: kNotificationActionTypeDestructive])
else if([actionType isEqualToString: kNotificationActionTypeAuthenticationRequired])
actionOption = UNNotificationActionOptionAuthenticationRequired;
else if([actionType isEqualToString:kNotificationActionTypeNone])
actionOption = UNNotificationActionOptionNone;
Expand Down
1 change: 0 additions & 1 deletion BlueShift-iOS-Extension-SDK/BlueShift_iOS_Extension_SDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ FOUNDATION_EXPORT const unsigned char BlueShift_iOS_Extension_SDKVersionString[]
#import "BlueShiftPushNotification.h"
#import "BlueShiftCarousalViewController.h"
#import "BlueshiftExtensionAnalyticsHelper.h"
#import "BlueShiftPushAnalytics.h"
#import "UIColor+BlueShiftHexString.h"
#import "BlueShiftiCarousel.h"
11 changes: 1 addition & 10 deletions BlueShift-iOS-Extension-SDK/BlueshiftExtensionAnalyticsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,11 @@ NS_ASSUME_NONNULL_BEGIN

@interface BlueshiftExtensionAnalyticsHelper : NSObject

/// This method is responsible to convert the push notification payload to the tracking attributes.
/// @param pushDetailsDictionary push notification payload
/// @returns push tracking attributes dictionary
+ (NSDictionary *)pushTrackParameterDictionaryForPushDetailsDictionary:(NSDictionary *)pushDetailsDictionary;

+ (NSString * _Nullable)getValueFrom:(NSDictionary *)notificationPayload usingKey:(NSString *)key;
+ (BOOL)isSendPushAnalytics:(NSDictionary *)userInfo;
+ (NSString *)getCurrentUTCTimestamp;

/// This method is used to get the push notification payload which can be used to fire delivered event externally by the host app.
/// This method adds the device specific attributes (device_id, app_name) to the push payload.
/// @param request Push notification request
/// @returns dictionary which includes device attributes and push payload
+ (NSDictionary * _Nullable)getPushNotificationDeliveredPayload:(UNNotificationRequest *)request API_AVAILABLE(ios(10.0));
+ (NSDictionary * _Nullable)getPushNotificationDeliveredPayload:(UNNotificationRequest *)request API_AVAILABLE(ios(10.0)) DEPRECATED_MSG_ATTRIBUTE("This method is deprecated as Blueshift iOS Extension SDK will no longer send the `delivered` event for push notifications and will be removed in the future SDK release.");;

@end

Expand Down
75 changes: 0 additions & 75 deletions BlueShift-iOS-Extension-SDK/BlueshiftExtensionAnalyticsHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,86 +6,11 @@
//

#import "BlueshiftExtensionAnalyticsHelper.h"
#import "BlueShiftPushAnalytics.h"
#import "BlueshiftExtensionConstants.h"

@implementation BlueshiftExtensionAnalyticsHelper

+ (NSDictionary *)pushTrackParameterDictionaryForPushDetailsDictionary:(NSDictionary *)pushDetailsDictionary {
NSMutableDictionary *pushTrackParametersMutableDictionary = [NSMutableDictionary dictionary];
if (pushDetailsDictionary) {
NSString *bsft_experiment_uuid = [self getValueFrom:pushDetailsDictionary usingKey:kNotificationExperimentIDKey];
NSString *bsft_user_uuid = [self getValueFrom:pushDetailsDictionary usingKey:kNotificationUserIDKey];
NSString *message_uuid = [self getValueFrom:pushDetailsDictionary usingKey:kNotificationMessageUDIDKey];
NSString *transactional_uuid = [self getValueFrom:pushDetailsDictionary usingKey:kNotificationTransactionIDKey];
NSString *sdkVersion = [[[NSBundle bundleForClass:self.class] infoDictionary] objectForKey:kCFBundleShortVersionString];
NSString *timestamp = [self getCurrentUTCTimestamp];
NSString *deviceId = (NSString *)[pushDetailsDictionary objectForKey:kDeviceID];
NSString *appName = (NSString *)[pushDetailsDictionary objectForKey:kAppName];

if (bsft_user_uuid) {
[pushTrackParametersMutableDictionary setObject:bsft_user_uuid forKey: kNotificationUIDKey];
}
if(bsft_experiment_uuid) {
[pushTrackParametersMutableDictionary setObject:bsft_experiment_uuid forKey: kNotificationEIDKey];
}
if (message_uuid) {
[pushTrackParametersMutableDictionary setObject:message_uuid forKey: kNotificationMIDKey];
}
if (transactional_uuid) {
[pushTrackParametersMutableDictionary setObject:transactional_uuid forKey: kNotificationTXNIDKey];
}
if (sdkVersion) {
[pushTrackParametersMutableDictionary setObject:sdkVersion forKey: kNotificationSDKVersionKey];
}
if (timestamp) {
[pushTrackParametersMutableDictionary setObject:timestamp forKey: kNotificationTimestampKey];
}
if (deviceId) {
[pushTrackParametersMutableDictionary setObject:deviceId forKey: kDeviceID];
}
if (appName) {
[pushTrackParametersMutableDictionary setObject:appName forKey: kAppName];
}
}
return [pushTrackParametersMutableDictionary copy];
}

+ (NSString * _Nullable)getValueFrom:(NSDictionary *)notificationPayload usingKey:(NSString *)key {
if (notificationPayload && key && ![key isEqualToString:@""]) {
if ([notificationPayload objectForKey:key]) {
return (NSString *)[notificationPayload objectForKey:key];
}
}
return nil;
}

+ (BOOL)isSendPushAnalytics:(NSDictionary *)userInfo {
if (userInfo && userInfo[kNotificationSeedListSend] && [userInfo[kNotificationSeedListSend] boolValue] == YES) {
return NO;
} else {
return YES;
}
}

+ (NSString *)getCurrentUTCTimestamp {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:kDefaultTimezoneFormat];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:kTimezoneUTC]];
return [dateFormatter stringFromDate:[NSDate date]];
}

+ (NSDictionary * _Nullable)getPushNotificationDeliveredPayload:(UNNotificationRequest *)request {
NSMutableDictionary *userInfo = [request.content.userInfo mutableCopy];
NSDictionary* deviceData = (NSDictionary*)[BlueShiftPushAnalytics getDeviceData];
if (userInfo && deviceData) {
if ([deviceData objectForKey:kDeviceID]) {
[userInfo setValue:[deviceData objectForKey:kDeviceID] forKey:kDeviceID];
}
if ([deviceData objectForKey:kAppName]) {
[userInfo setValue:[deviceData objectForKey:kAppName] forKey:kAppName];
}
}
return userInfo;
}

Expand Down
Loading

0 comments on commit a0ecb1b

Please sign in to comment.