Skip to content

Commit

Permalink
fix: Remove unnecessary badge number functionality (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
einsteinx2 committed May 15, 2024
1 parent 3c6aee8 commit 266612f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 53 deletions.
5 changes: 0 additions & 5 deletions mParticle-Apple-SDK/Utils/MPApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ extern NSString * _Nonnull const kMPApplicationInformationKey;
@property (nonatomic, strong, readonly, nullable) NSString *version __attribute__((const));
@property (nonatomic, readonly) MPEnvironment environment __attribute__((const));

#if TARGET_OS_IOS == 1
@property (nonatomic, strong, readonly, nullable) NSNumber *badgeNumber;
#endif

+ (nullable NSString *)appStoreReceipt;
+ (void)markInitialLaunchTime;
+ (void)updateLastUseDate:(nonnull NSDate *)date;
+ (void)updateLaunchCountsAndDates;
+ (void)updateStoredVersionAndBuildNumbers;
+ (void)updateBadgeNumber;
+ (nonnull NSDictionary *)appImageInfo;
+ (nullable UIApplication *)sharedUIApplication;
- (nonnull NSDictionary<NSString *, id> *)dictionaryRepresentation;
Expand Down
44 changes: 0 additions & 44 deletions mParticle-Apple-SDK/Utils/MPApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
NSString *const kMPAppStoredVersionKey = @"asv";
NSString *const kMPAppStoredBuildKey = @"asb";
NSString *const kMPAppEnvironmentKey = @"env";
NSString *const kMPAppBadgeNumberKey = @"bn";
NSString *const kMPAppStoreReceiptKey = @"asr";
NSString *const kMPAppImageBaseAddressKey = @"iba";
NSString *const kMPAppImageSizeKey = @"is";
Expand Down Expand Up @@ -69,10 +68,6 @@ @interface MParticle ()

@property (nonatomic, strong, readonly) MPStateMachine *stateMachine;

#if TARGET_OS_IOS == 1
@property (nonatomic, strong, readwrite, nullable) NSNumber *badgeNumber;
#endif

@end

@interface MPApplication() {
Expand Down Expand Up @@ -298,24 +293,6 @@ + (UIApplication *)sharedUIApplication {
return nil;
}

#if TARGET_OS_IOS == 1
- (NSNumber *)badgeNumber {
if (![MPStateMachine isAppExtension]) {
MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults];
NSNumber *badgeNumber = userDefaults[kMPAppBadgeNumberKey];
return badgeNumber.integerValue != 0 ? badgeNumber : nil;
}
return nil;
}

- (void)setBadgeNumber:(NSNumber * _Nullable)badgeNumber {
if (![MPStateMachine isAppExtension]) {
MPIUserDefaults *userDefaults = [MPIUserDefaults standardUserDefaults];
userDefaults[kMPAppBadgeNumberKey] = badgeNumber;
}
}
#endif

- (NSDictionary *)searchAdsAttribution {
return MParticle.sharedInstance.stateMachine.searchAdsInfo;
}
Expand Down Expand Up @@ -386,20 +363,6 @@ + (void)updateStoredVersionAndBuildNumbers {
application.storedBuild = application.build;
}

+ (void)updateBadgeNumber {
#if TARGET_OS_IOS == 1
if ([NSThread isMainThread]) {
MPApplication *application = [[MPApplication alloc] init];
application.badgeNumber = @([MPApplication sharedUIApplication].applicationIconBadgeNumber);
} else {
dispatch_async(dispatch_get_main_queue(), ^{
MPApplication *application = [[MPApplication alloc] init];
application.badgeNumber = @([MPApplication sharedUIApplication].applicationIconBadgeNumber);
});
}
#endif
}

+ (NSDictionary *)appImageInfo {
struct uuid_command uuid = {0};
uintptr_t baseaddr = 0;
Expand Down Expand Up @@ -510,13 +473,6 @@ + (NSDictionary *)appImageInfo {
applicationInfo[kMPAppStoreReceiptKey] = [MPApplication appStoreReceipt];
}

#if TARGET_OS_IOS == 1
NSNumber *badgeNumber = self.badgeNumber;
if (badgeNumber != nil) {
applicationInfo[kMPAppBadgeNumberKey] = badgeNumber;
}
#endif

appInfo = (NSDictionary *)applicationInfo;

return appInfo;
Expand Down
5 changes: 1 addition & 4 deletions mParticle-Apple-SDK/Utils/MPStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ - (instancetype)init {

[MPApplication markInitialLaunchTime];
[MPApplication updateLaunchCountsAndDates];
[MPApplication updateBadgeNumber];
});
}

Expand Down Expand Up @@ -260,12 +259,11 @@ - (void)resetTriggers {
- (void)handleApplicationDidEnterBackground:(NSNotification *)notification {
[MPApplication updateLastUseDate:_launchDate];
_backgrounded = YES;

__weak MPStateMachine *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
__strong MPStateMachine *strongSelf = weakSelf;
strongSelf.launchInfo = nil;
[MPApplication updateBadgeNumber];
});
}

Expand All @@ -275,7 +273,6 @@ - (void)handleApplicationWillEnterForeground:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
__strong MPStateMachine *strongSelf = weakSelf;
strongSelf->_backgrounded = NO;
[MPApplication updateBadgeNumber];
});
}

Expand Down

0 comments on commit 266612f

Please sign in to comment.