File tree Expand file tree Collapse file tree 4 files changed +37
-20
lines changed
OneSignalOutcomes/Source/OutcomeEvents Expand file tree Collapse file tree 4 files changed +37
-20
lines changed Original file line number Diff line number Diff line change 5252 appId : (NSString * _Nonnull)appId
5353 pushSubscriptionId : (NSString * _Nonnull)pushSubscriptionId
5454 onesignalId : (NSString * _Nonnull)onesignalId
55- influenceParams : (NSArray <OSFocusInfluenceParam *> *_Nonnull)influenceParams ;
55+ influenceParams : (NSArray <OSFocusInfluenceParam *> * _Nonnull)influenceParams
56+ onSuccess : (OSResultSuccessBlock _Nonnull)successBlock
57+ onFailure : (OSFailureBlock _Nonnull)failureBlock ;
5658
5759@end
Original file line number Diff line number Diff line change @@ -108,22 +108,24 @@ - (void)sendSessionEndOutcomes:(NSNumber * _Nonnull)timeElapsed
108108 appId : (NSString * _Nonnull)appId
109109 pushSubscriptionId : (NSString * _Nonnull)pushSubscriptionId
110110 onesignalId : (NSString * _Nonnull)onesignalId
111- influenceParams : (NSArray <OSFocusInfluenceParam *> * _Nonnull)influenceParams {
112- // Don't send influenced session with time < 1 seconds
113- if ([timeElapsed intValue ] < 1 ) {
114- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" sendSessionEndOutcomes not sending active time %@ " , timeElapsed]];
115- return ;
116- }
117- // TODO: What to do onSuccess and onFailure
111+ influenceParams : (NSArray <OSFocusInfluenceParam *> * _Nonnull)influenceParams
112+ onSuccess : (OSResultSuccessBlock _Nonnull)successBlock
113+ onFailure : (OSFailureBlock _Nonnull)failureBlock {
118114 [OneSignalClient.sharedClient executeRequest: [OSRequestSendSessionEndOutcomes
119115 withActiveTime: timeElapsed
120116 appId: appId
121117 pushSubscriptionId: pushSubscriptionId
122118 onesignalId: onesignalId
123119 influenceParams: influenceParams] onSuccess: ^(NSDictionary *result) {
124- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: @" sendSessionEndOutcomes attributed succeed" ];
120+ [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: @" OneSignalOutcomeEventsController:sendSessionEndOutcomes attributed succeed" ];
121+ if (successBlock) {
122+ successBlock (result);
123+ }
125124 } onFailure: ^(NSError *error) {
126- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: @" sendSessionEndOutcomes attributed failed" ];
125+ [OneSignalLog onesignalLog: ONE_S_LL_ERROR message: @" OneSignalOutcomeEventsController:sendSessionEndOutcomes attributed failed" ];
126+ if (failureBlock) {
127+ failureBlock (error);
128+ }
127129 }];
128130}
129131
Original file line number Diff line number Diff line change 3030#import " OSAttributedFocusTimeProcessor.h"
3131
3232@interface OneSignal ()
33- + (BOOL )sendSessionEndOutcomes : (NSNumber *)totalTimeActive params : (OSFocusCallParams *)params ;
33+ + (void )sendSessionEndOutcomes : (NSNumber *)totalTimeActive params : (OSFocusCallParams *)params onSuccess : (OSResultSuccessBlock _Nonnull) successBlock onFailure : (OSFailureBlock _Nonnull) failureBlock ;
3434@end
3535
3636@implementation OSAttributedFocusTimeProcessor {
@@ -73,6 +73,12 @@ - (void)sendUnsentActiveTime:(OSFocusCallParams *)params {
7373}
7474
7575- (void )sendOnFocusCallWithParams : (OSFocusCallParams *)params totalTimeActive : (NSTimeInterval )totalTimeActive {
76+ // Don't send influenced session with time < 1 seconds
77+ if (totalTimeActive < 1 ) {
78+ [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" sendSessionEndOutcomes not sending active time %f " , totalTimeActive]];
79+ return ;
80+ }
81+
7682 [OSBackgroundTaskManager beginBackgroundTask: ATTRIBUTED_FOCUS_TASK];
7783
7884 if (params.onSessionEnded ) {
Original file line number Diff line number Diff line change @@ -698,26 +698,33 @@ + (UNMutableNotificationContent*)serviceExtensionTimeWillExpireRequest:(UNNotifi
698698 Start of outcome module
699699 */
700700
701- // Returns if we can send this, meaning we have a subscription_id and onesignal_id
702- + (BOOL )sendSessionEndOutcomes : (NSNumber *)totalTimeActive params : (OSFocusCallParams *)params {
701+ + (void )sendSessionEndOutcomes : (NSNumber *)totalTimeActive params : (OSFocusCallParams *)params onSuccess : (OSResultSuccessBlock _Nonnull)successBlock onFailure : (OSFailureBlock _Nonnull)failureBlock {
703702 if (![OSOutcomes sharedController ]) {
704703 [OneSignalLog onesignalLog: ONE_S_LL_ERROR message: @" Make sure OneSignal init is called first" ];
705- return false ;
704+ if (failureBlock) {
705+ failureBlock ([NSError errorWithDomain: @" onesignal" code: 0 userInfo: @{@" error" : @" Missing outcomes controller." }]);
706+ }
707+ return ;
706708 }
707709
708710 NSString * onesignalId = OneSignalUserManagerImpl.sharedInstance .onesignalId ;
709711 NSString * pushSubscriptionId = OneSignalUserManagerImpl.sharedInstance .pushSubscriptionId ;
710712
711713 if (!onesignalId || !pushSubscriptionId) {
712- return false ;
714+ if (failureBlock) {
715+ failureBlock ([NSError errorWithDomain: @" onesignal" code: 0 userInfo: @{@" error" : @" Missing onesignalId or pushSubscriptionId." }]);
716+ }
717+ return ;
718+
713719 }
714720
715721 [OSOutcomes.sharedController sendSessionEndOutcomes: totalTimeActive
716- appId: appId
717- pushSubscriptionId: pushSubscriptionId
718- onesignalId: onesignalId
719- influenceParams: params.influenceParams];
720- return true ;
722+ appId: appId
723+ pushSubscriptionId: pushSubscriptionId
724+ onesignalId: onesignalId
725+ influenceParams: params.influenceParams
726+ onSuccess: successBlock
727+ onFailure: failureBlock];
721728}
722729
723730@end
You can’t perform that action at this time.
0 commit comments