Skip to content

Commit

Permalink
Hack to set the HasRequestedNotificationPermission
Browse files Browse the repository at this point in the history
If it is not set and the user has consented
This fixes
e-mission/e-mission-docs#1094 (comment)

Testing done:

```
$ npx cordova build ios
** BUILD SUCCEEDED **
```
  • Loading branch information
shankari committed Oct 9, 2024
1 parent 1c417e8 commit 7b0120f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ios/BEMDataCollection.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "SensorControlBackgroundChecker.h"
#import <CoreLocation/CoreLocation.h>

static NSString* const HAS_REQUESTED_NOTIFS_KEY = @"HasRequestedNotificationPermission";

@implementation BEMDataCollection

- (void)pluginInitialize
Expand Down Expand Up @@ -48,6 +50,18 @@ - (id)settingForKey:(NSString*)key

- (void)initWithConsent {
self.tripDiaryStateMachine = [TripDiaryStateMachine instance];
// Backwards compat hack to ensure that, if an existing user, with a user
// who installed the app before we started filling in
// `HasRequestedNotificationPermission` flag, and tries to re-enable
// notifications after disabling them through the settings
// https://github.com/e-mission/e-mission-docs/issues/1094#issuecomment-2403052620
if (![[NSUserDefaults standardUserDefaults] boolForKey:HAS_REQUESTED_NOTIFS_KEY]) {
// before version 1.9.0, notifications were required. So if the user consented,
// we must have requested notifications
// after version 1.9.0, we always set it before showing the notification,
// so we should never get here after 1.9.0
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:HAS_REQUESTED_NOTIFS_KEY];
}
[SensorControlBackgroundChecker checkAppState];
NSDictionary* emptyOptions = @{};
[AppDelegate didFinishLaunchingWithOptions:emptyOptions];
Expand Down

0 comments on commit 7b0120f

Please sign in to comment.