diff --git a/Analytics/Classes/Integrations/SEGIntegration.h b/Analytics/Classes/Integrations/SEGIntegration.h index 13c8b00b6..5c69d229d 100644 --- a/Analytics/Classes/Integrations/SEGIntegration.h +++ b/Analytics/Classes/Integrations/SEGIntegration.h @@ -59,6 +59,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)receivedRemoteNotification:(NSDictionary *)userInfo; - (void)failedToRegisterForRemoteNotificationsWithError:(NSError *)error; - (void)registeredForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; +- (void)putDeviceToken:(NSString *)deviceToken; - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo; // Callbacks for app state changes diff --git a/Analytics/Classes/Integrations/SEGIntegrationsManager.m b/Analytics/Classes/Integrations/SEGIntegrationsManager.m index 3292f3cf8..c1730bd20 100644 --- a/Analytics/Classes/Integrations/SEGIntegrationsManager.m +++ b/Analytics/Classes/Integrations/SEGIntegrationsManager.m @@ -253,6 +253,11 @@ - (void)registeredForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken [self callIntegrationsWithSelector:_cmd arguments:@[ deviceToken ] options:nil sync:true]; } +- (void)putDeviceToken:(NSString *)deviceToken +{ + [self callIntegrationsWithSelector:_cmd arguments:@[ deviceToken ] options:nil sync:true]; +} + - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo { [self callIntegrationsWithSelector:_cmd arguments:@[ identifier, userInfo ] options:nil sync:true]; @@ -518,6 +523,8 @@ - (SEGEventType)eventTypeFromSelector:(SEL)selector result = SEGEventTypeFailedToRegisterForRemoteNotifications; } else if ([selectorString hasPrefix:@"registeredForRemoteNotificationsWithDeviceToken"]) { result = SEGEventTypeRegisteredForRemoteNotifications; + } else if ([selectorString hasPrefix:@"putDeviceToken"]) { + result = SEGEventTypePuttingDeviceToken; } else if ([selectorString hasPrefix:@"handleActionWithIdentifier"]) { result = SEGEventTypeHandleActionWithForRemoteNotification; } else if ([selectorString hasPrefix:@"continueUserActivity"]) { @@ -679,6 +686,9 @@ - (void)context:(SEGContext *)context next:(void (^_Nonnull)(SEGContext *_Nullab [self registeredForRemoteNotificationsWithDeviceToken: [(SEGRemoteNotificationPayload *)context.payload deviceToken]]; break; + case SEGEventTypePuttingDeviceToken: + [self putDeviceToken:[(SEGPuttingDeviceTokenPayload *)context.payload deviceToken]]; + break; case SEGEventTypeHandleActionWithForRemoteNotification: { SEGRemoteNotificationPayload *payload = (SEGRemoteNotificationPayload *)context.payload; [self handleActionWithIdentifier:payload.actionIdentifier diff --git a/Analytics/Classes/Integrations/SEGPayload.h b/Analytics/Classes/Integrations/SEGPayload.h index cd4ca09ad..08f70b6e9 100644 --- a/Analytics/Classes/Integrations/SEGPayload.h +++ b/Analytics/Classes/Integrations/SEGPayload.h @@ -58,3 +58,9 @@ NS_ASSUME_NONNULL_END @property (nonatomic, strong, nullable) NSData *deviceToken; @end + +@interface SEGPuttingDeviceTokenPayload : SEGPayload + +@property (nonatomic, strong, nonnull) NSString *deviceToken; + +@end diff --git a/Analytics/Classes/Integrations/SEGPayload.m b/Analytics/Classes/Integrations/SEGPayload.m index a56fb9268..bb74da655 100644 --- a/Analytics/Classes/Integrations/SEGPayload.m +++ b/Analytics/Classes/Integrations/SEGPayload.m @@ -24,6 +24,10 @@ @implementation SEGRemoteNotificationPayload @end +@implementation SEGPuttingDeviceTokenPayload + +@end + @implementation SEGContinueUserActivityPayload diff --git a/Analytics/Classes/Internal/SEGSegmentIntegration.m b/Analytics/Classes/Internal/SEGSegmentIntegration.m index a74b94487..e1d0f1993 100644 --- a/Analytics/Classes/Internal/SEGSegmentIntegration.m +++ b/Analytics/Classes/Internal/SEGSegmentIntegration.m @@ -426,6 +426,11 @@ - (void)registeredForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken [self.cachedStaticContext[@"device"] setObject:[token copy] forKey:@"token"]; } +- (void)putDeviceToken:(NSString *)deviceToken +{ + [self.cachedStaticContext[@"device"] setObject:deviceToken forKey:@"token"]; +} + - (void)continueUserActivity:(NSUserActivity *)activity { if ([activity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { diff --git a/Analytics/Classes/Middlewares/SEGContext.h b/Analytics/Classes/Middlewares/SEGContext.h index 30ac8353c..77bf5d9b5 100644 --- a/Analytics/Classes/Middlewares/SEGContext.h +++ b/Analytics/Classes/Middlewares/SEGContext.h @@ -27,6 +27,7 @@ typedef NS_ENUM(NSInteger, SEGEventType) { SEGEventTypeReceivedRemoteNotification, SEGEventTypeFailedToRegisterForRemoteNotifications, SEGEventTypeRegisteredForRemoteNotifications, + SEGEventTypePuttingDeviceToken, SEGEventTypeHandleActionWithForRemoteNotification, // Application Lifecycle diff --git a/Analytics/Classes/SEGAnalytics.h b/Analytics/Classes/SEGAnalytics.h index 9bab573f2..2dc2b48b7 100644 --- a/Analytics/Classes/SEGAnalytics.h +++ b/Analytics/Classes/SEGAnalytics.h @@ -148,6 +148,16 @@ NS_ASSUME_NONNULL_BEGIN - (void)receivedRemoteNotification:(NSDictionary *)userInfo; - (void)failedToRegisterForRemoteNotificationsWithError:(NSError *)error; - (void)registeredForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; + +/*! +@method + +@abstract +Manually set a device token (for example when using Firebase Cloud Messaging tokens). +*/ +- (void)putDeviceToken:(NSString *)deviceToken; + +// todo: docs - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo; - (void)continueUserActivity:(NSUserActivity *)activity; - (void)openURL:(NSURL *)url options:(NSDictionary *)options; diff --git a/Analytics/Classes/SEGAnalytics.m b/Analytics/Classes/SEGAnalytics.m index 6f0bd2983..2ad582244 100644 --- a/Analytics/Classes/SEGAnalytics.m +++ b/Analytics/Classes/SEGAnalytics.m @@ -342,6 +342,13 @@ - (void)registeredForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken [self run:SEGEventTypeRegisteredForRemoteNotifications payload:payload]; } +- (void)putDeviceToken:(NSString *)deviceToken +{ + SEGPuttingDeviceTokenPayload *payload = [[SEGPuttingDeviceTokenPayload alloc] init]; + payload.deviceToken = deviceToken; + [self run:SEGEventTypePuttingDeviceToken payload:payload]; +} + - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo { SEGRemoteNotificationPayload *payload = [[SEGRemoteNotificationPayload alloc] init];