@@ -179,9 +179,13 @@ - (MPURL *)configURL {
179179 NSString *urlString = [NSString stringWithFormat: configURLFormat, kMPURLScheme , kMPURLHostConfig , kMPConfigVersion , stateMachine.apiKey, kMPConfigURL , [application.version percentEscape ], kMParticleSDKVersion ];
180180 NSURL *defaultURL = [NSURL URLWithString: urlString];
181181
182- urlString = [NSString stringWithFormat: configURLFormat, kMPURLScheme , configHost, kMPConfigVersion , stateMachine.apiKey, kMPConfigURL , [application.version percentEscape ], kMParticleSDKVersion ];
182+ if (customHost && networkOptions.overridesConfigSubdirectory ) {
183+ MPILogWarning (@" MPNetworkOptions: customBaseURL with overridesConfigSubdirectory is unsupported for CDN routing; overridesConfigSubdirectory will be ignored." );
184+ }
185+ NSString *configVersion = customHost ? @" config/v4" : kMPConfigVersion ;
186+ urlString = [NSString stringWithFormat: configURLFormat, kMPURLScheme , configHost, configVersion, stateMachine.apiKey, kMPConfigURL , [application.version percentEscape ], kMParticleSDKVersion ];
183187
184- if (networkOptions.overridesConfigSubdirectory ) {
188+ if (!customHost && networkOptions.overridesConfigSubdirectory ) {
185189 NSString *configURLFormat = [urlFormatOverride stringByAppendingString: @" ?av=%@ &sv=%@ " ];
186190 urlString = [NSString stringWithFormat: configURLFormat, kMPURLScheme , configHost, stateMachine.apiKey, kMPConfigURL , [application.version percentEscape ], kMParticleSDKVersion ];
187191 }
@@ -207,10 +211,15 @@ - (MPURL *)eventURLForUpload:(MPUpload *)mpUpload {
207211 NSString *urlString = [NSString stringWithFormat: urlFormat, kMPURLScheme , self .defaultEventHost, kMPEventsVersion , mpUpload.uploadSettings.apiKey, kMPEventsURL ];
208212 NSURL *defaultURL = [NSURL URLWithString: urlString];
209213
210- if (mpUpload.uploadSettings .overridesEventsSubdirectory ) {
214+ BOOL usingCustomBaseURL = [MParticle sharedInstance ].networkOptions .customBaseURL != nil ;
215+ if (usingCustomBaseURL && mpUpload.uploadSettings .overridesEventsSubdirectory ) {
216+ MPILogWarning (@" MPNetworkOptions: customBaseURL with overridesEventsSubdirectory is unsupported for CDN routing; overridesEventsSubdirectory will be ignored." );
217+ }
218+ NSString *eventsVersion = usingCustomBaseURL ? @" nativeevents/v2" : kMPEventsVersion ;
219+ if (!usingCustomBaseURL && mpUpload.uploadSettings .overridesEventsSubdirectory ) {
211220 urlString = [NSString stringWithFormat: urlFormatOverride, kMPURLScheme , eventHost, mpUpload.uploadSettings.apiKey, kMPEventsURL ];
212221 } else {
213- urlString = [NSString stringWithFormat: urlFormat, kMPURLScheme , eventHost, kMPEventsVersion , mpUpload.uploadSettings.apiKey, kMPEventsURL ];
222+ urlString = [NSString stringWithFormat: urlFormat, kMPURLScheme , eventHost, eventsVersion , mpUpload.uploadSettings.apiKey, kMPEventsURL ];
214223 }
215224
216225 NSURL *modifiedURL = [NSURL URLWithString: urlString];
@@ -234,12 +243,16 @@ - (MPURL *)audienceURL {
234243 NSString *urlString = [NSString stringWithFormat: audienceURLFormat, kMPURLScheme , self .defaultEventHost, kMPAudienceVersion , stateMachine.apiKey, kMPAudienceURL , [MPPersistenceController_PRIVATE mpId ]];
235244 NSURL *defaultURL = [NSURL URLWithString: urlString];
236245
237- if (networkOptions.overridesEventsSubdirectory ) {
246+ if (customHost && networkOptions.overridesEventsSubdirectory ) {
247+ MPILogWarning (@" MPNetworkOptions: customBaseURL with overridesEventsSubdirectory is unsupported for CDN routing; overridesEventsSubdirectory will be ignored." );
248+ }
249+ NSString *audienceVersion = customHost ? @" nativeevents/v1" : kMPAudienceVersion ;
250+ if (!customHost && networkOptions.overridesEventsSubdirectory ) {
238251 audienceURLFormat = [urlFormatOverride stringByAppendingString: @" ?mpid=%@ " ];
239252 urlString = [NSString stringWithFormat: audienceURLFormat, kMPURLScheme , eventHost, kMPAudienceVersion , stateMachine.apiKey, kMPAudienceURL , [MPPersistenceController_PRIVATE mpId ]];
240253 } else {
241254 audienceURLFormat = [urlFormat stringByAppendingString: @" ?mpid=%@ " ];
242- urlString = [NSString stringWithFormat: audienceURLFormat, kMPURLScheme , eventHost, kMPAudienceVersion , stateMachine.apiKey, kMPAudienceURL , [MPPersistenceController_PRIVATE mpId ]];
255+ urlString = [NSString stringWithFormat: audienceURLFormat, kMPURLScheme , eventHost, audienceVersion , stateMachine.apiKey, kMPAudienceURL , [MPPersistenceController_PRIVATE mpId ]];
243256 }
244257
245258 NSURL *modifiedURL = [NSURL URLWithString: urlString];
@@ -303,10 +316,14 @@ - (MPURL *)identityURL:(NSString *)pathComponent {
303316 NSString *urlString = [NSString stringWithFormat: identityURLFormat, kMPURLScheme , self .defaultIdentityHost, kMPIdentityVersion , pathComponent];
304317 NSURL *defaultURL = [NSURL URLWithString: urlString];
305318
306- if (identityNetworkOptions.overridesIdentitySubdirectory ) {
319+ if (identityCustomHost && identityNetworkOptions.overridesIdentitySubdirectory ) {
320+ MPILogWarning (@" MPNetworkOptions: customBaseURL with overridesIdentitySubdirectory is unsupported for CDN routing; overridesIdentitySubdirectory will be ignored." );
321+ }
322+ NSString *identityVersion = identityCustomHost ? @" identity/v1" : kMPIdentityVersion ;
323+ if (!identityCustomHost && identityNetworkOptions.overridesIdentitySubdirectory ) {
307324 urlString = [NSString stringWithFormat: identityURLFormatOverride, kMPURLScheme , identityHost, pathComponent];
308325 } else {
309- urlString = [NSString stringWithFormat: identityURLFormat, kMPURLScheme , identityHost, kMPIdentityVersion , pathComponent];
326+ urlString = [NSString stringWithFormat: identityURLFormat, kMPURLScheme , identityHost, identityVersion , pathComponent];
310327 }
311328
312329 NSURL *modifiedURL = [NSURL URLWithString: urlString];
@@ -341,10 +358,14 @@ - (MPURL *)modifyURL {
341358 NSString *urlString = [NSString stringWithFormat: modifyURLFormat, kMPURLScheme , self .defaultIdentityHost, kMPIdentityVersion , [MPPersistenceController_PRIVATE mpId ], pathComponent];
342359 NSURL *defaultURL = [NSURL URLWithString: urlString];
343360
344- if (modifyNetworkOptions.overridesIdentitySubdirectory ) {
361+ if (modifyCustomHost && modifyNetworkOptions.overridesIdentitySubdirectory ) {
362+ MPILogWarning (@" MPNetworkOptions: customBaseURL with overridesIdentitySubdirectory is unsupported for CDN routing; overridesIdentitySubdirectory will be ignored." );
363+ }
364+ NSString *modifyVersion = modifyCustomHost ? @" identity/v1" : kMPIdentityVersion ;
365+ if (!modifyCustomHost && modifyNetworkOptions.overridesIdentitySubdirectory ) {
345366 urlString = [NSString stringWithFormat: modifyURLFormatOverride, kMPURLScheme , identityHost, [MPPersistenceController_PRIVATE mpId ], pathComponent];
346367 } else {
347- urlString = [NSString stringWithFormat: modifyURLFormat, kMPURLScheme , identityHost, kMPIdentityVersion , [MPPersistenceController_PRIVATE mpId ], pathComponent];
368+ urlString = [NSString stringWithFormat: modifyURLFormat, kMPURLScheme , identityHost, modifyVersion , [MPPersistenceController_PRIVATE mpId ], pathComponent];
348369 }
349370
350371 NSURL *modifiedURL = [NSURL URLWithString: urlString];
@@ -371,16 +392,21 @@ - (MPURL *)aliasURLForUpload:(MPUpload *)mpUpload {
371392 NSString *urlString = [NSString stringWithFormat: aliasURLFormat, kMPURLScheme , self .defaultEventHost, kMPIdentityVersion , kMPIdentityKey , mpUpload.uploadSettings.apiKey, pathComponent];
372393 NSURL *defaultURL = [NSURL URLWithString: urlString];
373394
395+ BOOL usingCustomBaseURLAlias = [MParticle sharedInstance ].networkOptions .customBaseURL != nil ;
374396 BOOL overrides = mpUpload.uploadSettings .overridesAliasSubdirectory ;
375397 if (!mpUpload.uploadSettings .eventsOnly && !mpUpload.uploadSettings .aliasHost ) {
376398 eventHost = mpUpload.uploadSettings .eventsHost ?: self.defaultEventHost ;
377399 overrides = mpUpload.uploadSettings .overridesEventsSubdirectory ;
378400 }
379401
380- if (overrides) {
402+ if (usingCustomBaseURLAlias && overrides) {
403+ MPILogWarning (@" MPNetworkOptions: customBaseURL with overridesAliasSubdirectory/overridesEventsSubdirectory is unsupported for CDN routing; subdirectory override will be ignored." );
404+ }
405+ NSString *aliasVersion = usingCustomBaseURLAlias ? @" nativeevents/v1" : kMPIdentityVersion ;
406+ if (!usingCustomBaseURLAlias && overrides) {
381407 urlString = [NSString stringWithFormat: aliasURLFormatOverride, kMPURLScheme , eventHost, mpUpload.uploadSettings.apiKey, pathComponent];
382408 } else {
383- urlString = [NSString stringWithFormat: aliasURLFormat, kMPURLScheme , eventHost, kMPIdentityVersion , kMPIdentityKey , mpUpload.uploadSettings.apiKey, pathComponent];
409+ urlString = [NSString stringWithFormat: aliasURLFormat, kMPURLScheme , eventHost, aliasVersion , kMPIdentityKey , mpUpload.uploadSettings.apiKey, pathComponent];
384410 }
385411
386412 NSURL *modifiedURL = [NSURL URLWithString: urlString];
0 commit comments