Skip to content

Commit

Permalink
Merge pull request #426 from RevenueCat/Logging-v2-part-1-strings
Browse files Browse the repository at this point in the history
Logging v2 part 1 strings
  • Loading branch information
tiinanguyen committed Dec 30, 2020
2 parents 0f790d2 + 2cb7ace commit 0eda629
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 49 deletions.
8 changes: 8 additions & 0 deletions Purchases.xcodeproj/project.pbxproj
Expand Up @@ -213,6 +213,8 @@
37E35F549AEB655AB6DA83B3 /* MockSKDiscount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E35EABF6D7AFE367718784 /* MockSKDiscount.swift */; };
37E35F67255A87BD86B39D43 /* MockReceiptParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E3558F697A939D2BBD7FEC /* MockReceiptParser.swift */; };
9A65DFDE258AD60A00DE00B0 /* LogIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65DFDD258AD60A00DE00B0 /* LogIntent.swift */; };
9A65E03625918B0500DE00B0 /* ConfigureStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65E03525918B0500DE00B0 /* ConfigureStrings.swift */; };
9A65E03B25918B0900DE00B0 /* PurchaserInfoStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65E03A25918B0900DE00B0 /* PurchaserInfoStrings.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -470,6 +472,8 @@
6B5DC754D48165CE32D8133B /* Pods_PurchasesCoreSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PurchasesCoreSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
84C3F1AC1D7E1E64341D3936 /* Pods_Purchases_PurchasesTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Purchases_PurchasesTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9A65DFDD258AD60A00DE00B0 /* LogIntent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogIntent.swift; sourceTree = "<group>"; };
9A65E03525918B0500DE00B0 /* ConfigureStrings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigureStrings.swift; sourceTree = "<group>"; };
9A65E03A25918B0900DE00B0 /* PurchaserInfoStrings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PurchaserInfoStrings.swift; sourceTree = "<group>"; };
A976872C3EDAC0B4F4B45481 /* Pods_PurchasesCoreSwift_PurchasesCoreSwiftTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PurchasesCoreSwift_PurchasesCoreSwiftTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -526,6 +530,8 @@
isa = PBXGroup;
children = (
2D11F5E0250FF886005A70E8 /* AttributionStrings.swift */,
9A65E03525918B0500DE00B0 /* ConfigureStrings.swift */,
9A65E03A25918B0900DE00B0 /* PurchaserInfoStrings.swift */,
37E3507939634ED5A9280544 /* Strings.swift */,
);
path = Strings;
Expand Down Expand Up @@ -1346,10 +1352,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9A65E03B25918B0900DE00B0 /* PurchaserInfoStrings.swift in Sources */,
2DDF41B624F6F387005BC22D /* ASN1ObjectIdentifierBuilder.swift in Sources */,
2DDF419624F6F331005BC22D /* ProductsRequestFactory.swift in Sources */,
2DDF419724F6F331005BC22D /* DateExtensions.swift in Sources */,
2DC5623024EC63730031F69B /* OperationDispatcher.swift in Sources */,
9A65E03625918B0500DE00B0 /* ConfigureStrings.swift in Sources */,
2D11F5E1250FF886005A70E8 /* AttributionStrings.swift in Sources */,
2DDF41B524F6F387005BC22D /* AppleReceiptBuilder.swift in Sources */,
2DDF41A324F6F331005BC22D /* ReceiptParser.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Purchases/Misc/RCSystemInfo.m
Expand Up @@ -103,7 +103,7 @@ + (void)setForceUniversalAppStore:(BOOL)forceUniversalAppStore {
+ (void)setProxyURL:(nullable NSURL *)newProxyURL {
proxyURL = newProxyURL;
if (newProxyURL) {
RCLog(@"Purchases is being configured using a proxy for RevenueCat with URL: %@", newProxyURL);
RCLog(RCStrings.configure.configuring_purchases_proxy_url_set, newProxyURL);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Purchases/Networking/RCBackend.m
Expand Up @@ -434,7 +434,7 @@ - (void)postSubscriberAttributes:(RCSubscriberAttributeDict)subscriberAttributes
appUserID:(NSString *)appUserID
completion:(nullable void (^)(NSError *_Nullable error))completion {
if (subscriberAttributes.count == 0) {
RCLog(@"called post subscriber attributes with an empty attributes dict!");
RCWarnLog(@"%@", RCStrings.attribution.empty_subscriber_attributes);
return;
}
NSString *escapedAppUserID = [self escapedAppUserID:appUserID];
Expand Down
66 changes: 34 additions & 32 deletions Purchases/Public/RCPurchases.m
Expand Up @@ -131,15 +131,15 @@ - (void)setFinishTransactions:(BOOL)finishTransactions {

+ (instancetype)sharedPurchases {
if (!_sharedPurchases) {
RCLog(@"There is no singleton instance. Make sure you configure Purchases before trying to get the default instance.");
RCWarnLog(@"%@", RCStrings.configure.no_singleton_instance);
}
return _sharedPurchases;
}

+ (void)setDefaultInstance:(RCPurchases *)instance {
@synchronized([RCPurchases class]) {
if (_sharedPurchases) {
RCLog(@"Purchases instance already set. Did you mean to configure two Purchases objects?");
RCLog(@"%@", RCStrings.configure.purchase_instance_already_set);
}
_sharedPurchases = instance;
}
Expand Down Expand Up @@ -265,9 +265,9 @@ - (instancetype)initWithAppUserID:(nullable NSString *)appUserID
introEligibilityCalculator:(RCIntroEligibilityCalculator *)introEligibilityCalculator
receiptParser:(RCReceiptParser *)receiptParser {
if (self = [super init]) {
RCDebugLog(@"Debug logging enabled.");
RCDebugLog(@"SDK Version - %@", self.class.frameworkVersion);
RCDebugLog(@"Initial App User ID - %@", appUserID);
RCDebugLog(@"%@", RCStrings.configure.debug_enabled);
RCDebugLog(RCStrings.configure.sdk_version, self.class.frameworkVersion);
RCDebugLog(RCStrings.configure.initial_app_user_id, appUserID);

self.requestFetcher = requestFetcher;
self.receiptFetcher = receiptFetcher;
Expand Down Expand Up @@ -340,7 +340,7 @@ - (void)dealloc {

- (void)setDelegate:(id <RCPurchasesDelegate>)delegate {
_delegate = delegate;
RCDebugLog(@"Delegate set");
RCDebugLog(@"%@", RCStrings.configure.delegate_set);

[self sendCachedPurchaserInfoIfAvailable];
}
Expand All @@ -366,10 +366,10 @@ + (void)addAttributionData:(NSDictionary *)data
fromNetwork:(RCAttributionNetwork)network
forNetworkUserId:(nullable NSString *)networkUserId {
if (_sharedPurchases) {
RCLog(@"%@", RCStrings.attribution.instance_configured_posting_attribution);
RCDebugLog(@"%@", RCStrings.attribution.instance_configured_posting_attribution);
[_sharedPurchases postAttributionData:data fromNetwork:network forNetworkUserId:networkUserId];
} else {
RCLog(@"%@", RCStrings.attribution.no_instance_configured_caching_attribution);
RCDebugLog(@"%@", RCStrings.attribution.no_instance_configured_caching_attribution);
[RCAttributionFetcher storePostponedAttributionData:data
fromNetwork:network
forNetworkUserId:networkUserId];
Expand Down Expand Up @@ -425,14 +425,15 @@ - (void)purchaserInfoWithCompletionBlock:(RCReceivePurchaserInfoBlock)completion
[self.systemInfo isApplicationBackgroundedWithCompletion:^(BOOL isAppBackgrounded) {
RCPurchaserInfo *infoFromCache = [self readPurchaserInfoFromCache];
if (infoFromCache) {
RCDebugLog(@"Vending purchaserInfo from cache");
RCDebugLog(@"%@", RCStrings.purchaserInfo.vending_cache);
CALL_IF_SET_ON_MAIN_THREAD(completion, infoFromCache, nil);
if ([self.deviceCache isPurchaserInfoCacheStaleForAppUserID:self.appUserID isAppBackgrounded:isAppBackgrounded]) {
RCDebugLog(@"Cache is stale, updating caches");
RCDebugLog(@"%@", isAppBackgrounded ? RCStrings.purchaserInfo.purchaserinfo_stale_updating_in_background : RCStrings.purchaserInfo.purchaserinfo_stale_updating_in_foreground);
[self fetchAndCachePurchaserInfoWithCompletion:nil isAppBackgrounded:isAppBackgrounded];
RCSuccessLog(@"%@", RCStrings.purchaserInfo.purchaserinfo_updated_from_network);
}
} else {
RCDebugLog(@"No cached purchaser info, fetching");
RCDebugLog(@"%@", RCStrings.purchaserInfo.no_cached_purchaserinfo);
[self fetchAndCachePurchaserInfoWithCompletion:completion isAppBackgrounded:isAppBackgrounded];
}
}];
Expand Down Expand Up @@ -729,7 +730,7 @@ - (void)paymentDiscountForProductDiscount:(SKProductDiscount *)discount
}

- (void)invalidatePurchaserInfoCache {
RCDebugLog(@"Purchaser info cache is invalidated");
RCDebugLog(@"%@", RCStrings.purchaserInfo.invalidating_purchaserinfo_cache);
[self.deviceCache clearPurchaserInfoCacheForAppUserID:self.appUserID];
}

Expand All @@ -741,92 +742,93 @@ - (void)presentCodeRedemptionSheet API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(tvos
#pragma mark Subcriber Attributes

- (void)setAttributes:(NSDictionary<NSString *, NSString *> *)attributes {
RCDebugLog(@"setAttributes called");
RCDebugLog(RCStrings.attribution.method_called, "setAttributes");
[self.subscriberAttributesManager setAttributes:attributes appUserID:self.appUserID];
}

- (void)setEmail:(nullable NSString *)email {
RCDebugLog(@"setEmail called");
RCDebugLog(RCStrings.attribution.method_called, "setEmail");
[self.subscriberAttributesManager setEmail:email appUserID:self.appUserID];
}

- (void)setPhoneNumber:(nullable NSString *)phoneNumber {
RCDebugLog(@"setPhoneNumber called");
RCDebugLog(RCStrings.attribution.method_called, "setPhoneNumber");
[self.subscriberAttributesManager setPhoneNumber:phoneNumber appUserID:self.appUserID];
}

- (void)setDisplayName:(nullable NSString *)displayName {
RCDebugLog(@"setDisplayName called");
RCDebugLog(RCStrings.attribution.method_called, "setDisplayName");
[self.subscriberAttributesManager setDisplayName:displayName appUserID:self.appUserID];
}

- (void)setPushToken:(nullable NSData *)pushToken {
RCDebugLog(@"setPushToken called");
RCDebugLog(RCStrings.attribution.method_called, "setPushToken");
[self.subscriberAttributesManager setPushToken:pushToken appUserID:self.appUserID];
}

- (void)_setPushTokenString:(nullable NSString *)pushToken {
RCDebugLog(@"setPushTokenString called");
RCDebugLog(RCStrings.attribution.method_called, "setPushTokenString");
[self.subscriberAttributesManager setPushTokenString:pushToken appUserID:self.appUserID];
}

- (void)setAdjustID:(nullable NSString *)adjustID {
RCDebugLog(@"setAdjustID called");
RCDebugLog(RCStrings.attribution.method_called, "setAdjustID");
[self.subscriberAttributesManager setAdjustID:adjustID appUserID:self.appUserID];
}

- (void)setAppsflyerID:(nullable NSString *)appsflyerID {
RCDebugLog(@"setAppsflyerID called");
RCDebugLog(RCStrings.attribution.method_called, "setAppsflyerID");
[self.subscriberAttributesManager setAppsflyerID:appsflyerID appUserID:self.appUserID];
}

- (void)setFBAnonymousID:(nullable NSString *)fbAnonymousID {
RCDebugLog(@"setFBAnonymousID called");
RCDebugLog(RCStrings.attribution.method_called, "setFBAnonymousID");
[self.subscriberAttributesManager setFBAnonymousID:fbAnonymousID appUserID:self.appUserID];
}

- (void)setMparticleID:(nullable NSString *)mparticleID {
RCDebugLog(@"setMparticleID called");
RCDebugLog(RCStrings.attribution.method_called, "setMparticleID");
[self.subscriberAttributesManager setMparticleID:mparticleID appUserID:self.appUserID];
}

- (void)setOnesignalID:(nullable NSString *)onesignalID {
RCDebugLog(@"setOnesignalID called");
RCDebugLog(RCStrings.attribution.method_called, "setOnesignalID");
[self.subscriberAttributesManager setOnesignalID:onesignalID appUserID:self.appUserID];
}

- (void)setMediaSource:(nullable NSString *)mediaSource {
RCDebugLog(@"setMediaSource called");
RCDebugLog(RCStrings.attribution.method_called, "setMediaSource");
[self.subscriberAttributesManager setMediaSource:mediaSource appUserID:self.appUserID];
}

- (void)setCampaign:(nullable NSString *)campaign {
RCDebugLog(@"setCampaign called");
RCDebugLog(RCStrings.attribution.method_called, "setCampaign");
[self.subscriberAttributesManager setCampaign:campaign appUserID:self.appUserID];
}

- (void)setAdGroup:(nullable NSString *)adGroup {
RCDebugLog(@"setAdGroup called");
RCDebugLog(RCStrings.attribution.method_called, "setAdGroup");
[self.subscriberAttributesManager setAdGroup:adGroup appUserID:self.appUserID];
}

- (void)setAd:(nullable NSString *)ad {
RCDebugLog(@"setAd called");
RCDebugLog(RCStrings.attribution.method_called, "setAd");
[self.subscriberAttributesManager setAd:ad appUserID:self.appUserID];
}

- (void)setKeyword:(nullable NSString *)keyword {
RCDebugLog(@"setKeyword called");
RCDebugLog(RCStrings.attribution.method_called, "setKeyword");
[self.subscriberAttributesManager setKeyword:keyword appUserID:self.appUserID];
}

- (void)setCreative:(nullable NSString *)creative {
RCDebugLog(@"setCreative called");
RCDebugLog(RCStrings.attribution.method_called, "setCreative");
[self.subscriberAttributesManager setCreative:creative appUserID:self.appUserID];
}

- (void)collectDeviceIdentifiers {
RCDebugLog(@"collectDeviceIdentifiers called");
RCDebugLog(RCStrings.attribution.method_called, "setAttributes");
[self.subscriberAttributesManager collectDeviceIdentifiersForAppUserID:self.appUserID];
}

Expand All @@ -849,7 +851,7 @@ - (void)sendCachedPurchaserInfoIfAvailable {
}

- (void)updateAllCachesIfNeeded {
RCDebugLog(@"applicationDidBecomeActive");
RCDebugLog(@"%@", RCStrings.configure.application_active);
[self.systemInfo isApplicationBackgroundedWithCompletion:^(BOOL isAppBackgrounded) {
if ([self.deviceCache isPurchaserInfoCacheStaleForAppUserID:self.appUserID isAppBackgrounded:isAppBackgrounded]) {
RCDebugLog(@"PurchaserInfo cache is stale, updating caches");
Expand Down Expand Up @@ -1073,9 +1075,9 @@ - (void)sendUpdatedPurchaserInfoToDelegateIfChanged:(RCPurchaserInfo *)info {
@synchronized (self) {
if (![self.lastSentPurchaserInfo isEqual:info]) {
if (self.lastSentPurchaserInfo) {
RCDebugLog(@"Purchaser info updated, sending to delegate");
RCDebugLog(@"%@", RCStrings.purchaserInfo.sending_updated_purchaserinfo_to_delegate);
} else {
RCDebugLog(@"Sending latest purchaser info to delegate");
RCDebugLog(@"%@", RCStrings.purchaserInfo.sending_latest_purchaserinfo_to_delegate);
}
self.lastSentPurchaserInfo = info;
[self.operationDispatcher dispatchOnMainThread:^{
Expand Down
8 changes: 4 additions & 4 deletions Purchases/Purchasing/RCAttributionFetcher.m
Expand Up @@ -89,7 +89,7 @@ - (nullable NSString *)identifierForAdvertisers {
NSUUID *identifierValue = [sharedManager valueForKey:identifierPropertyName];
return identifierValue.UUIDString;
} else {
RCDebugLog(@"AdSupport framework not imported. Attribution data incomplete.");
RCWarnLog(@"%@", RCStrings.configure.adsupport_not_imported);
}
}
return nil;
Expand Down Expand Up @@ -125,10 +125,10 @@ - (void)postAttributionData:(NSDictionary *)data
fromNetwork:(RCAttributionNetwork)network
forNetworkUserId:(nullable NSString *)networkUserId {
if (data[@"rc_appsflyer_id"]) {
RCErrorLog(@"⚠️ The parameter key rc_appsflyer_id is deprecated. Pass networkUserId to addAttribution instead. ⚠️");
RCWarnLog(@"%@", RCStrings.attribution.appsflyer_id_deprecated);
}
if (network == RCAttributionNetworkAppsFlyer && networkUserId == nil) {
RCErrorLog(@"⚠️ The parameter networkUserId is REQUIRED for AppsFlyer. ⚠️");
RCWarnLog(@"%@", RCStrings.attribution.networkuserid_required_for_appsflyer);
}
NSString *appUserID = self.identityManager.currentAppUserID;
NSString *networkKey = [NSString stringWithFormat:@"%ld", (long) network];
Expand All @@ -139,7 +139,7 @@ - (void)postAttributionData:(NSDictionary *)data
NSString *newValueForNetwork = [NSString stringWithFormat:@"%@_%@", identifierForAdvertisers, networkUserId];

if ([latestSentToNetwork isEqualToString:newValueForNetwork]) {
RCDebugLog(@"Attribution data is the same as latest. Skipping.");
RCDebugLog(@"%@", RCStrings.attribution.skip_same_attributes);
} else {
NSMutableDictionary<NSString *, NSString *> *newDictToCache =
[NSMutableDictionary dictionaryWithDictionary:dictOfLatestNetworkIdsAndAdvertisingIdsSentToNetworks];
Expand Down
Expand Up @@ -24,9 +24,9 @@ - (RCSubscriberAttributeDict)unsyncedAttributesByKey {
NSString *appUserID = self.appUserID;
RCSubscriberAttributeDict unsyncedAttributes = [self.subscriberAttributesManager
unsyncedAttributesByKeyForAppUserID:appUserID];
RCLog(@"found %lu unsynced attributes for appUserID: %@", (unsigned long)unsyncedAttributes.count, appUserID);
RCDebugLog(RCStrings.attribution.unsynced_attributes_count, (unsigned long)unsyncedAttributes.count, appUserID);
if (unsyncedAttributes.count > 0) {
RCLog(@"unsynced attributes: %@", unsyncedAttributes);
RCDebugLog(RCStrings.attribution.unsynced_attributes, unsyncedAttributes);
}

return unsyncedAttributes;
Expand All @@ -40,7 +40,7 @@ - (void)markAttributesAsSyncedIfNeeded:(nullable RCSubscriberAttributeDict)synce
}

if (error.subscriberAttributesErrors) {
RCLog(@"Subscriber attributes errors: %@", error.subscriberAttributesErrors);
RCErrorLog(RCStrings.attribution.subscriber_attributes_error, error.subscriberAttributesErrors);
}
[self.subscriberAttributesManager markAttributesAsSynced:syncedAttributes appUserID:appUserID];
}
Expand Down
Expand Up @@ -141,12 +141,12 @@ - (void)handleAttributesSyncedForAppUserID:(NSString *)syncingAppUserID
currentAppUserID:(NSString *)currentAppUserID
error:(NSError *)error {
if (error == nil) {
RCLog(@"Subscriber attributes synced successfully for appUserID: %@", syncingAppUserID);
RCSuccessLog(RCStrings.attribution.attributes_sync_success, syncingAppUserID);
if (![syncingAppUserID isEqualToString:currentAppUserID]) {
[self.deviceCache deleteAttributesIfSyncedForAppUserID:syncingAppUserID];
}
} else {
RCErrorLog(@"error when syncing subscriber attributes. Details: %@\n UserInfo:%@",
RCErrorLog(RCStrings.attribution.attributes_sync_error,
error.localizedDescription,
error.userInfo);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ - (void)markAttributesAsSynced:(RCSubscriberAttributeDict)syncedAttributes
return;
}

RCLog(@"marking the following attributes as synced for appUserID: %@: %@", appUserID, syncedAttributes);
RCLog(RCStrings.attribution.marking_attributes_synced, appUserID, syncedAttributes);
@synchronized (self) {
RCSubscriberAttributeMutableDict
unsyncedAttributes = [self unsyncedAttributesByKeyForAppUserID:appUserID].mutableCopy;
Expand Down

0 comments on commit 0eda629

Please sign in to comment.