Fixes notification actions not showing

Checks notifiction allowed at every app becom active
Added error message if notifications are not allowed
This commit is contained in:
Christophe Deschamps 2022-02-04 09:34:16 +01:00
parent 5374471827
commit 8a3030d4fb
3 changed files with 39 additions and 11 deletions

View file

@ -159,6 +159,33 @@
[self handleShortcut:_shortcutItem];
_shortcutItem = nil;
}
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError *_Nullable error) {
if (error)
LOGD(error.description);
if (!granted) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *errView =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"Push notification not allowed", nil)
message:NSLocalizedString(@"Push notifications are required to receive calls and messages.", nil)
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
}];
[errView addAction:defaultAction];
[PhoneMainView.instance.mainViewController presentViewController:errView animated:YES completion:nil];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self configureUINotification];
});
}
}];
}
#pragma deploymate push "ignored-api-availability"
@ -227,15 +254,9 @@
options:UNNotificationCategoryOptionCustomDismissAction];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError *_Nullable error) {
// Enable or disable features based on authorization.
if (error)
LOGD(error.description);
}];
NSSet *categories = [NSSet setWithObjects:cat_call, cat_msg, video_call, cat_zrtp, nil];
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories];
}
#pragma deploymate pop
@ -278,9 +299,7 @@
BOOL background_mode = [instance lpConfigBoolForKey:@"backgroundmode_preference"];
BOOL start_at_boot = [instance lpConfigBoolForKey:@"start_at_boot_preference"];
[self configureUINotification];
if (state == UIApplicationStateBackground) {
// we've been woken up directly to background;
if (!start_at_boot || !background_mode) {
@ -523,6 +542,10 @@
completionHandler(UNNotificationPresentationOptionAlert);
}
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {

View file

@ -26,6 +26,8 @@
<dict>
<key>UNNotificationExtensionCategory</key>
<string>msg_cat</string>
<key>UNNotificationExtensionDefaultContentHidden</key>
<false/>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>0.01</real>
<key>UNNotificationExtensionOverridesDefaultTitle</key>

View file

@ -46,6 +46,7 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
#endif
NSLog("[msgNotificationContent] start msgNotificationContent extension")
let replyAction = UNTextInputNotificationAction(identifier: "Reply",
title: NSLocalizedString("Reply", comment: ""),
options: [],
@ -61,7 +62,9 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
coreStopped = false
}
func didReceive(_ notification: UNNotification) {}
func didReceive(_ notification: UNNotification) {
VFSUtil.log("Notification received \(notification.request.content.userInfo) category \(notification.request.content.categoryIdentifier)",.info)
}
func didReceive(_ response: UNNotificationResponse,
completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {