Consistent flow for enabling notifications.
This commit is contained in:
parent
514c383310
commit
00ac788f4f
@ -131,11 +131,11 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
countlyConfig.deviceID = [PearlKeyChain deviceIdentifier];
|
countlyConfig.deviceID = [PearlKeyChain deviceIdentifier];
|
||||||
countlyConfig.secretSalt = decrypt( countlySalt );
|
countlyConfig.secretSalt = decrypt( countlySalt );
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
countlyConfig.pushTestMode = CLYPushTestModeDevelopment;
|
|
||||||
countlyConfig.enableDebug = YES;
|
countlyConfig.enableDebug = YES;
|
||||||
|
countlyConfig.pushTestMode = CLYPushTestModeDevelopment;
|
||||||
#elif ! PUBLIC
|
#elif ! PUBLIC
|
||||||
countlyConfig.pushTestMode = CLYPushTestModeTestFlightOrAdHoc;
|
|
||||||
countlyConfig.enableDebug = NO;
|
countlyConfig.enableDebug = NO;
|
||||||
|
countlyConfig.pushTestMode = CLYPushTestModeTestFlightOrAdHoc;
|
||||||
#endif
|
#endif
|
||||||
[Countly.sharedInstance startWithConfig:countlyConfig];
|
[Countly.sharedInstance startWithConfig:countlyConfig];
|
||||||
}
|
}
|
||||||
@ -203,6 +203,8 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
.window makeKeyAndOrderFront:self];
|
.window makeKeyAndOrderFront:self];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self enableNotifications];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillResignActive:(NSNotification *)notification {
|
- (void)applicationWillResignActive:(NSNotification *)notification {
|
||||||
@ -228,6 +230,41 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
return NSTerminateNow;
|
return NSTerminateNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)enableNotifications {
|
||||||
|
|
||||||
|
[Countly.sharedInstance giveConsentForFeature:CLYConsentPushNotifications];
|
||||||
|
if (@available( macOS 10.14, * )) {
|
||||||
|
[Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionProvisional | UNAuthorizationOptionAlert
|
||||||
|
completionHandler:^(BOOL granted, NSError *error) {
|
||||||
|
if (!granted)
|
||||||
|
err( @"No provisional notification permission: %@", error );
|
||||||
|
|
||||||
|
[self askNotifications];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self askNotifications];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)askNotifications {
|
||||||
|
|
||||||
|
PearlMainQueue( ^{
|
||||||
|
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"notificationsDecided"]) {
|
||||||
|
if (@available( macOS 10.14, * )) {
|
||||||
|
[Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionAlert completionHandler:
|
||||||
|
^(BOOL granted, NSError *error) {
|
||||||
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[Countly.sharedInstance askForNotificationPermission];
|
||||||
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - State
|
#pragma mark - State
|
||||||
|
|
||||||
- (void)setActiveUser:(MPUserEntity *)activeUser {
|
- (void)setActiveUser:(MPUserEntity *)activeUser {
|
||||||
@ -727,39 +764,32 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
// Send info
|
// Send info
|
||||||
|
NSArray *countlyFeatures = @[
|
||||||
|
CLYConsentSessions, CLYConsentEvents, CLYConsentUserDetails, CLYConsentCrashReporting, CLYConsentViewTracking, CLYConsentStarRating
|
||||||
|
];
|
||||||
if ([[MPConfig get].sendInfo boolValue]) {
|
if ([[MPConfig get].sendInfo boolValue]) {
|
||||||
PearlMainQueue( ^{
|
[Countly.sharedInstance giveConsentForFeatures:countlyFeatures];
|
||||||
[Countly.sharedInstance giveConsentForAllFeatures];
|
|
||||||
[Countly.sharedInstance askForNotificationPermission];
|
|
||||||
});
|
|
||||||
|
|
||||||
if ([PearlLogger get].printLevel > PearlLogLevelInfo)
|
if ([PearlLogger get].printLevel > PearlLogLevelInfo)
|
||||||
[PearlLogger get].printLevel = PearlLogLevelInfo;
|
[PearlLogger get].printLevel = PearlLogLevelInfo;
|
||||||
|
|
||||||
NSMutableDictionary *prefs = [NSMutableDictionary new];
|
|
||||||
prefs[@"rememberLogin"] = [MPConfig get].rememberLogin;
|
|
||||||
prefs[@"sendInfo"] = [MPConfig get].sendInfo;
|
|
||||||
prefs[@"fullScreen"] = [MPMacConfig get].fullScreen;
|
|
||||||
prefs[@"firstRun"] = [PearlConfig get].firstRun;
|
|
||||||
prefs[@"launchCount"] = [PearlConfig get].launchCount;
|
|
||||||
prefs[@"askForReviews"] = [PearlConfig get].askForReviews;
|
|
||||||
prefs[@"reviewAfterLaunches"] = [PearlConfig get].reviewAfterLaunches;
|
|
||||||
prefs[@"reviewedVersion"] = [PearlConfig get].reviewedVersion;
|
|
||||||
prefs[@"simulator"] = @([PearlDeviceUtils isSimulator]);
|
|
||||||
prefs[@"encrypted"] = @([PearlDeviceUtils isAppEncrypted]);
|
|
||||||
prefs[@"platform"] = [PearlDeviceUtils platform];
|
|
||||||
|
|
||||||
[SentrySDK.currentHub getClient].options.enabled = @YES;
|
[SentrySDK.currentHub getClient].options.enabled = @YES;
|
||||||
[SentrySDK configureScope:^(SentryScope *scope) {
|
[SentrySDK configureScope:^(SentryScope *scope) {
|
||||||
for (NSString *pref in prefs.allKeys)
|
[scope setExtraValue:[MPConfig get].rememberLogin forKey:@"rememberLogin"];
|
||||||
[scope setExtraValue:prefs[pref] forKey:pref];
|
[scope setExtraValue:[MPConfig get].sendInfo forKey:@"sendInfo"];
|
||||||
|
[scope setExtraValue:[MPMacConfig get].fullScreen forKey:@"fullScreen"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].firstRun forKey:@"firstRun"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].launchCount forKey:@"launchCount"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].askForReviews forKey:@"askForReviews"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].reviewAfterLaunches forKey:@"reviewAfterLaunches"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].reviewedVersion forKey:@"reviewedVersion"];
|
||||||
|
[scope setExtraValue:@([PearlDeviceUtils isSimulator]) forKey:@"simulator"];
|
||||||
|
[scope setExtraValue:@([PearlDeviceUtils isAppEncrypted]) forKey:@"encrypted"];
|
||||||
|
[scope setExtraValue:[PearlDeviceUtils platform] forKey:@"platform"];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[SentrySDK.currentHub getClient].options.enabled = @NO;
|
[SentrySDK.currentHub getClient].options.enabled = @NO;
|
||||||
PearlMainQueue( ^{
|
[Countly.sharedInstance cancelConsentForFeatures:countlyFeatures];
|
||||||
[Countly.sharedInstance cancelConsentForAllFeatures];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,15 +102,16 @@
|
|||||||
countlyConfig.appKey = decrypt( countlyKey );
|
countlyConfig.appKey = decrypt( countlyKey );
|
||||||
countlyConfig.features = @[ CLYPushNotifications, CLYAutoViewTracking ];
|
countlyConfig.features = @[ CLYPushNotifications, CLYAutoViewTracking ];
|
||||||
countlyConfig.requiresConsent = YES;
|
countlyConfig.requiresConsent = YES;
|
||||||
#if DEBUG
|
|
||||||
countlyConfig.pushTestMode = CLYPushTestModeDevelopment;
|
|
||||||
#elif ! PUBLIC
|
|
||||||
countlyConfig.pushTestMode = CLYPushTestModeTestFlightOrAdHoc;
|
|
||||||
#endif
|
|
||||||
countlyConfig.alwaysUsePOST = YES;
|
countlyConfig.alwaysUsePOST = YES;
|
||||||
countlyConfig.deviceID = [PearlKeyChain deviceIdentifier];
|
countlyConfig.deviceID = [PearlKeyChain deviceIdentifier];
|
||||||
countlyConfig.secretSalt = decrypt( countlySalt );
|
countlyConfig.secretSalt = decrypt( countlySalt );
|
||||||
|
#if DEBUG
|
||||||
countlyConfig.enableDebug = YES;
|
countlyConfig.enableDebug = YES;
|
||||||
|
countlyConfig.pushTestMode = CLYPushTestModeDevelopment;
|
||||||
|
#elif ! PUBLIC
|
||||||
|
countlyConfig.enableDebug = NO;
|
||||||
|
countlyConfig.pushTestMode = CLYPushTestModeTestFlightOrAdHoc;
|
||||||
|
#endif
|
||||||
[Countly.sharedInstance startWithConfig:countlyConfig];
|
[Countly.sharedInstance startWithConfig:countlyConfig];
|
||||||
|
|
||||||
#if ! DEBUG
|
#if ! DEBUG
|
||||||
@ -171,30 +172,11 @@
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if (@available( iOS 12, * )) {
|
|
||||||
[Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionProvisional completionHandler:
|
|
||||||
^(BOOL granted, NSError *error) {
|
|
||||||
inf( @"provisional: %d: %@", granted, error );
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PearlMainQueueOperation( ^{
|
PearlMainQueueOperation( ^{
|
||||||
if ([[MPiOSConfig get].showSetup boolValue])
|
if ([[MPiOSConfig get].showSetup boolValue])
|
||||||
[self.navigationController performSegueWithIdentifier:@"setup" sender:self];
|
[self.navigationController performSegueWithIdentifier:@"setup" sender:self];
|
||||||
|
|
||||||
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"notificationsDecided"]) {
|
[self enableNotifications];
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Coming Soon" message:
|
|
||||||
@"Master Password is rolling out a new modern personal security platform and we're excited to bring you along.\n\n"
|
|
||||||
@"When it's time, we'll send you a notification to help you make an effortless transition."
|
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Thanks" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
||||||
[Countly.sharedInstance askForNotificationPermission];
|
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"];
|
|
||||||
}]];
|
|
||||||
[(self.navigationController.presentedViewController?: (UIViewController *)self.navigationController)
|
|
||||||
presentViewController:alert animated:YES completion:nil];
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@catch (id exception) {
|
@catch (id exception) {
|
||||||
@ -247,6 +229,49 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)enableNotifications {
|
||||||
|
|
||||||
|
[Countly.sharedInstance giveConsentForFeature:CLYConsentPushNotifications];
|
||||||
|
if (@available( iOS 12, * )) {
|
||||||
|
[Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionProvisional | UNAuthorizationOptionAlert
|
||||||
|
completionHandler:^(BOOL granted, NSError *error) {
|
||||||
|
if (!granted)
|
||||||
|
err( @"No provisional notification permission: %@", error );
|
||||||
|
|
||||||
|
[self askNotifications];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self askNotifications];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)askNotifications {
|
||||||
|
|
||||||
|
PearlMainQueue( ^{
|
||||||
|
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"notificationsDecided"]) {
|
||||||
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Coming Soon" message:
|
||||||
|
@"Master Password is rolling out a new modern personal security platform and we're excited to bring you along.\n\n"
|
||||||
|
@"When it's time, we'll send you a notification to help you make an effortless transition."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[alert addAction:[UIAlertAction actionWithTitle:@"Thanks" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||||
|
if (@available( iOS 12, * )) {
|
||||||
|
[Countly.sharedInstance askForNotificationPermissionWithOptions:UNAuthorizationOptionAlert completionHandler:
|
||||||
|
^(BOOL granted, NSError *error) {
|
||||||
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[Countly.sharedInstance askForNotificationPermission];
|
||||||
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"notificationsDecided"];
|
||||||
|
}
|
||||||
|
}]];
|
||||||
|
[(self.navigationController.presentedViewController?: (UIViewController *)self.navigationController)
|
||||||
|
presentViewController:alert animated:YES completion:nil];
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
- (void)importSites:(NSString *)importData {
|
- (void)importSites:(NSString *)importData {
|
||||||
|
|
||||||
if ([NSThread isMainThread]) {
|
if ([NSThread isMainThread]) {
|
||||||
@ -655,41 +680,39 @@
|
|||||||
[PearlLogger get].historyLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelTrace: PearlLogLevelInfo;
|
[PearlLogger get].historyLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelTrace: PearlLogLevelInfo;
|
||||||
|
|
||||||
// Send info
|
// Send info
|
||||||
|
NSArray *countlyFeatures = @[
|
||||||
|
CLYConsentSessions, CLYConsentEvents, CLYConsentUserDetails, CLYConsentCrashReporting, CLYConsentViewTracking, CLYConsentStarRating
|
||||||
|
];
|
||||||
if ([[MPConfig get].sendInfo boolValue]) {
|
if ([[MPConfig get].sendInfo boolValue]) {
|
||||||
[Countly.sharedInstance giveConsentForAllFeatures];
|
[Countly.sharedInstance giveConsentForFeatures:countlyFeatures];
|
||||||
|
|
||||||
if ([PearlLogger get].printLevel > PearlLogLevelInfo)
|
if ([PearlLogger get].printLevel > PearlLogLevelInfo)
|
||||||
[PearlLogger get].printLevel = PearlLogLevelInfo;
|
[PearlLogger get].printLevel = PearlLogLevelInfo;
|
||||||
|
|
||||||
NSMutableDictionary *prefs = [NSMutableDictionary new];
|
|
||||||
prefs[@"rememberLogin"] = [MPConfig get].rememberLogin;
|
|
||||||
prefs[@"sendInfo"] = [MPConfig get].sendInfo;
|
|
||||||
prefs[@"helpHidden"] = [MPiOSConfig get].helpHidden;
|
|
||||||
prefs[@"showQuickStart"] = [MPiOSConfig get].showSetup;
|
|
||||||
prefs[@"firstRun"] = [PearlConfig get].firstRun;
|
|
||||||
prefs[@"launchCount"] = [PearlConfig get].launchCount;
|
|
||||||
prefs[@"askForReviews"] = [PearlConfig get].askForReviews;
|
|
||||||
prefs[@"reviewAfterLaunches"] = [PearlConfig get].reviewAfterLaunches;
|
|
||||||
prefs[@"reviewedVersion"] = [PearlConfig get].reviewedVersion;
|
|
||||||
prefs[@"simulator"] = @([PearlDeviceUtils isSimulator]);
|
|
||||||
prefs[@"encrypted"] = @([PearlDeviceUtils isAppEncrypted]);
|
|
||||||
prefs[@"jailbroken"] = @([PearlDeviceUtils isJailbroken]);
|
|
||||||
prefs[@"platform"] = [PearlDeviceUtils platform];
|
|
||||||
#ifdef APPSTORE
|
|
||||||
prefs[@"reviewedVersion"] = @([PearlDeviceUtils isAppEncrypted]);
|
|
||||||
#else
|
|
||||||
prefs[@"reviewedVersion"] = @(YES);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[SentrySDK.currentHub getClient].options.enabled = @YES;
|
[SentrySDK.currentHub getClient].options.enabled = @YES;
|
||||||
[SentrySDK configureScope:^(SentryScope *scope) {
|
[SentrySDK configureScope:^(SentryScope *scope) {
|
||||||
for (NSString *pref in prefs.allKeys)
|
[scope setExtraValue:[MPConfig get].rememberLogin forKey:@"rememberLogin"];
|
||||||
[scope setExtraValue:prefs[pref] forKey:pref];
|
[scope setExtraValue:[MPConfig get].sendInfo forKey:@"sendInfo"];
|
||||||
|
[scope setExtraValue:[MPiOSConfig get].helpHidden forKey:@"helpHidden"];
|
||||||
|
[scope setExtraValue:[MPiOSConfig get].showSetup forKey:@"showQuickStart"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].firstRun forKey:@"firstRun"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].launchCount forKey:@"launchCount"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].askForReviews forKey:@"askForReviews"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].reviewAfterLaunches forKey:@"reviewAfterLaunches"];
|
||||||
|
[scope setExtraValue:[PearlConfig get].reviewedVersion forKey:@"reviewedVersion"];
|
||||||
|
[scope setExtraValue:@([PearlDeviceUtils isSimulator]) forKey:@"simulator"];
|
||||||
|
[scope setExtraValue:@([PearlDeviceUtils isAppEncrypted]) forKey:@"encrypted"];
|
||||||
|
[scope setExtraValue:@([PearlDeviceUtils isJailbroken]) forKey:@"jailbroken"];
|
||||||
|
[scope setExtraValue:[PearlDeviceUtils platform] forKey:@"platform"];
|
||||||
|
#ifdef APPSTORE
|
||||||
|
[scope setExtraValue:@([PearlDeviceUtils isAppEncrypted]) forKey:@"reviewedVersion"];
|
||||||
|
#else
|
||||||
|
[scope setExtraValue:@(NO) forKey:@"reviewedVersion"];
|
||||||
|
#endif
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[SentrySDK.currentHub getClient].options.enabled = @NO;
|
[SentrySDK.currentHub getClient].options.enabled = @NO;
|
||||||
[Countly.sharedInstance cancelConsentForAllFeatures];
|
[Countly.sharedInstance cancelConsentForFeatures:countlyFeatures];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<key>Title</key>
|
<key>Title</key>
|
||||||
<string>Version</string>
|
<string>Version</string>
|
||||||
<key>Key</key>
|
<key>Key</key>
|
||||||
<string>unset</string>
|
<string>version</string>
|
||||||
<key>Type</key>
|
<key>Type</key>
|
||||||
<string>PSTitleValueSpecifier</string>
|
<string>PSTitleValueSpecifier</string>
|
||||||
</dict>
|
</dict>
|
||||||
@ -28,7 +28,7 @@
|
|||||||
<key>Title</key>
|
<key>Title</key>
|
||||||
<string>Build</string>
|
<string>Build</string>
|
||||||
<key>Key</key>
|
<key>Key</key>
|
||||||
<string>unset</string>
|
<string>build</string>
|
||||||
<key>Type</key>
|
<key>Type</key>
|
||||||
<string>PSTitleValueSpecifier</string>
|
<string>PSTitleValueSpecifier</string>
|
||||||
</dict>
|
</dict>
|
||||||
@ -40,7 +40,7 @@
|
|||||||
<key>Type</key>
|
<key>Type</key>
|
||||||
<string>PSTitleValueSpecifier</string>
|
<string>PSTitleValueSpecifier</string>
|
||||||
<key>Key</key>
|
<key>Key</key>
|
||||||
<string>unset</string>
|
<string>copyright</string>
|
||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
<key>Type</key>
|
<key>Type</key>
|
||||||
|
Loading…
Reference in New Issue
Block a user