Skip to content

Commit

Permalink
Merge pull request e-mission#241 from JGreenlee/userdefaults-HasReque…
Browse files Browse the repository at this point in the history
…stedNotificationPermission

revert back to UserDefaults for "HasRequestedNotificationPermission"
  • Loading branch information
shankari authored Oct 9, 2024
2 parents 90ca5ed + dca2446 commit bc1d845
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
18 changes: 5 additions & 13 deletions src/android/verification/SensorControlForegroundDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import edu.berkeley.eecs.emission.cordova.tracker.Constants;
import edu.berkeley.eecs.emission.cordova.unifiedlogger.Log;
import edu.berkeley.eecs.emission.cordova.usercache.UserCacheFactory;


/*
Expand Down Expand Up @@ -777,18 +776,11 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case SensorControlConstants.ENABLE_NOTIFICATIONS:
Log.d(mAct, TAG, requestCode + " is our code, handling callback");
Log.d(mAct, TAG, "Got notification callback from launching app settings");
try {
JSONObject jo = new JSONObject();
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();
} else {
cordovaCallback.error(cordova.getActivity().getString(R.string.notifications_blocked));
}
} catch (JSONException e) {
cordovaCallback.error(e.getLocalizedMessage());
if (SensorControlChecks.checkNotificationsEnabled(cordova.getActivity())) {
SensorControlBackgroundChecker.restartFSMIfStartState(cordova.getActivity());
cordovaCallback.success();
} else {
cordovaCallback.error(cordova.getActivity().getString(R.string.notifications_blocked));
}
break;
case SensorControlConstants.REMOVE_UNUSED_APP_RESTRICTIONS:
Expand Down
8 changes: 2 additions & 6 deletions src/ios/Verification/SensorControlForegroundDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#import "LocalNotificationManager.h"
#import "BEMAppDelegate.h"
#import "BEMActivitySync.h"
#import "BEMBuiltinUserCache.h"
#import "DataUtils.h"

#import <CoreMotion/CoreMotion.h>

Expand Down Expand Up @@ -264,11 +262,12 @@ - (void)checkAndPromptNotificationPermission {
NSString* callbackId = [command callbackId];
@try {
// 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) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:HAS_REQUESTED_NOTIFS_KEY]) {
NSLog(@"Already prompted request for user notification. Launching app settings.");
[AppDelegate registerForegroundDelegate:self];
[self openAppSettings];
} else {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:HAS_REQUESTED_NOTIFS_KEY];
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
NSLog(@"Requesting user notification settings");
UIUserNotificationSettings* requestedSettings = [TripDiarySensorControlChecks REQUESTED_NOTIFICATION_TYPES];
Expand All @@ -287,9 +286,6 @@ - (void)checkAndPromptNotificationPermission {
}

- (void) didRegisterUserNotificationSettings:(UIUserNotificationSettings*)newSettings {
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 bc1d845

Please sign in to comment.