1616#import " BNCLog.h"
1717#import " Branch.h"
1818#import " NSString+Branch.h"
19+ #import " BNCApplication.h"
1920
2021@interface BNCServerInterface ()
2122@property (strong ) NSString *requestEndpoint;
@@ -528,6 +529,12 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
528529 [self safeSetValue: [deviceInfo userAgentString ] forKey: @" user_agent" onDict: dict];
529530
530531 [self safeSetValue: [deviceInfo optedInStatus ] forKey: BRANCH_REQUEST_KEY_OPTED_IN_STATUS onDict: dict];
532+
533+ if ([self installDateIsRecent ] && [deviceInfo isFirstOptIn ]) {
534+ [self safeSetValue: @(deviceInfo.isFirstOptIn) forKey: BRANCH_REQUEST_KEY_FIRST_OPT_IN onDict: dict];
535+ [BNCPreferenceHelper preferenceHelper ].hasOptedInBefore = YES ;
536+ }
537+
531538 [self safeSetValue: @(deviceInfo.isAdTrackingEnabled) forKey: BRANCH_REQUEST_KEY_AD_TRACKING_ENABLED onDict: dict];
532539
533540 [self safeSetValue: deviceInfo.applicationVersion forKey: @" app_version" onDict: dict];
@@ -541,6 +548,20 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
541548 }
542549}
543550
551+ // we do not need to send first_opt_in, if the install is older than 30 days
552+ - (BOOL )installDateIsRecent {
553+ // NSTimeInterval maxTimeSinceInstall = 60.0;
554+ NSTimeInterval maxTimeSinceInstall = 3600.0 * 24.0 * 30 ;
555+ NSDate *now = [NSDate date ];
556+ NSDate *maxDate = [[BNCApplication currentApplication ].currentInstallDate dateByAddingTimeInterval: maxTimeSinceInstall];
557+
558+ if ([now compare: maxDate] == NSOrderedDescending) {
559+ return NO ;
560+ } else {
561+ return YES ;
562+ }
563+ }
564+
544565- (NSMutableDictionary *)updateDeviceInfoToParams : (NSDictionary *)params {
545566 NSMutableDictionary *extendedParams=[[NSMutableDictionary alloc ] init ];
546567 [extendedParams addEntriesFromDictionary: params];
0 commit comments