Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to set the HasRequestedNotificationPermission #242

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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