Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to put device token #881

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Analytics/Classes/Integrations/SEGIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Analytics/Classes/Integrations/SEGIntegrationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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"]) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Analytics/Classes/Integrations/SEGPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Analytics/Classes/Integrations/SEGPayload.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ @implementation SEGRemoteNotificationPayload

@end

@implementation SEGPuttingDeviceTokenPayload

@end


@implementation SEGContinueUserActivityPayload

Expand Down
5 changes: 5 additions & 0 deletions Analytics/Classes/Internal/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/Middlewares/SEGContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef NS_ENUM(NSInteger, SEGEventType) {
SEGEventTypeReceivedRemoteNotification,
SEGEventTypeFailedToRegisterForRemoteNotifications,
SEGEventTypeRegisteredForRemoteNotifications,
SEGEventTypePuttingDeviceToken,
SEGEventTypeHandleActionWithForRemoteNotification,

// Application Lifecycle
Expand Down
10 changes: 10 additions & 0 deletions Analytics/Classes/SEGAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down