Skip to content

Commit

Permalink
store ts in 'HasRequestedNotificationPermission'; declare as constant
Browse files Browse the repository at this point in the history
  • Loading branch information
JGreenlee committed Oct 8, 2024
1 parent 153e3f2 commit e062604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/android/verification/SensorControlForegroundDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

public class SensorControlForegroundDelegate {
public static final String TAG = "SensorPermissionsAndSettingsForegroundDelegate";
private static final String HAS_REQUESTED_NOTIFS_KEY = "HasRequestedNotificationPermission";

private CordovaPlugin plugin = null;
private CordovaInterface cordova = null;
Expand Down Expand Up @@ -777,8 +778,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(mAct, TAG, requestCode + " is our code, handling callback");
Log.d(mAct, TAG, "Got notification callback from launching app settings");
JSONObject jo = new JSONObject();
jo.put("value", true);
UserCacheFactory.getUserCache(cordova.getActivity()).putLocalStorage("HasRequestedNotificationPermission", jo);
jo.put("ts", System.currentTimeMillis() / 1000);
UserCacheFactory.getUserCache(cordova.getActivity()).putLocalStorage(HAS_REQUESTED_NOTIFS_KEY, jo);
if (SensorControlChecks.checkNotificationsEnabled(cordova.getActivity())) {
SensorControlBackgroundChecker.restartFSMIfStartState(cordova.getActivity());
cordovaCallback.success();
Expand Down
11 changes: 8 additions & 3 deletions src/ios/Verification/SensorControlForegroundDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "BEMAppDelegate.h"
#import "BEMActivitySync.h"
#import "BEMBuiltinUserCache.h"
#import "DataUtils.h"

#import <CoreMotion/CoreMotion.h>

Expand All @@ -14,6 +15,8 @@ @interface SensorControlForegroundDelegate() {
}
@end

static NSString* const HAS_REQUESTED_NOTIFS_KEY = @"HasRequestedNotificationPermission";

@implementation SensorControlForegroundDelegate

/*
Expand Down Expand Up @@ -260,7 +263,8 @@ -(void) didRecieveFitnessPermission:(BOOL)isPermitted
- (void)checkAndPromptNotificationPermission {
NSString* callbackId = [command callbackId];
@try {
if ([[BuiltinUserCache database] getLocalStorage:@"HasRequestedNotificationPermission" withMetadata:NO] != NULL) {
// If we have prompted in the past, the popup will not work. Instead, we'll open app settings
if ([[BuiltinUserCache database] getLocalStorage:HAS_REQUESTED_NOTIFS_KEY withMetadata:NO] != NULL) {
NSLog(@"Already prompted request for user notification. Launching app settings.");
[AppDelegate registerForegroundDelegate:self];
[self openAppSettings];
Expand All @@ -283,8 +287,9 @@ - (void)checkAndPromptNotificationPermission {
}

- (void) didRegisterUserNotificationSettings:(UIUserNotificationSettings*)newSettings {
[[BuiltinUserCache database] putLocalStorage:@"HasRequestedNotificationPermission"
jsonValue:@{ @"value" : @(TRUE) }];
NSDate* now = [NSDate date];
[[BuiltinUserCache database] putLocalStorage:HAS_REQUESTED_NOTIFS_KEY
jsonValue:@{ @"ts": @(now.timeIntervalSince1970) }];
NSString* callbackId = [command callbackId];
UIUserNotificationSettings* requestedSettings = [TripDiarySensorControlChecks REQUESTED_NOTIFICATION_TYPES];
if (requestedSettings.types == newSettings.types) {
Expand Down

0 comments on commit e062604

Please sign in to comment.