Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Allow notifications to "Deliver Quietly" #865

Merged
merged 6 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Changes to be released in next version
* MXKRoomViewController: Fix initial timeline position when viewing a room for the second time.

⚠️ API Changes
*
* MXKAccountManager: `isAPNSAvailable` and `isPushAvailable` now only indicate the availability of notifications and not their visibility as well (vector-im/element-ios/issues/2368).

🗣 Translations
*
Expand Down
2 changes: 1 addition & 1 deletion MatrixKit/Models/Account/MXKAccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern NSString *const MXKAccountManagerDataType;
@property (nonatomic, copy) NSData *apnsDeviceToken;

/**
The APNS status: YES when app is registered for remote notif, and devive token is known.
The APNS status: YES when app is registered for remote notif, and device token is known.
*/
@property (nonatomic) BOOL isAPNSAvailable;

Expand Down
20 changes: 6 additions & 14 deletions MatrixKit/Models/Account/MXKAccountManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,15 @@ - (void)setApnsDeviceToken:(NSData *)apnsDeviceToken
- (BOOL)isAPNSAvailable
{
// [UIApplication isRegisteredForRemoteNotifications] tells whether your app can receive
// remote notifications or not. However receiving remote notifications does not mean it
// will also display them to the user.
// To check whether the user allowed or denied remote notification or in fact changed
// the notifications permissions later in iOS setting, we have to call
// [UIApplication currentUserNotificationSettings].
// remote notifications or not. Receiving remote notifications does not guarantee it will
// display them to the user as they may have notifications set to deliver quietly.

BOOL isRemoteNotificationsAllowed = NO;

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
if (sharedApplication)
{
UIUserNotificationSettings *settings = [sharedApplication currentUserNotificationSettings];
isRemoteNotificationsAllowed = (settings.types != UIUserNotificationTypeNone);
isRemoteNotificationsAllowed = [sharedApplication isRegisteredForRemoteNotifications];

MXLogDebug(@"[MXKAccountManager][Push] isAPNSAvailable: The user %@ remote notification", (isRemoteNotificationsAllowed ? @"allowed" : @"denied"));
}
Expand Down Expand Up @@ -572,19 +568,15 @@ - (void)setPushDeviceToken:(NSData *)pushDeviceToken withPushOptions:(NSDictiona
- (BOOL)isPushAvailable
{
// [UIApplication isRegisteredForRemoteNotifications] tells whether your app can receive
// remote notifications or not. However receiving remote notifications does not mean it
// will also display them to the user.
// To check whether the user allowed or denied remote notification or in fact changed
// the notifications permissions later in iOS setting, we have to call
// [UIApplication currentUserNotificationSettings].
// remote notifications or not. Receiving remote notifications does not guarantee it will
// display them to the user as they may have notifications set to deliver quietly.

BOOL isRemoteNotificationsAllowed = NO;

UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
if (sharedApplication)
{
UIUserNotificationSettings *settings = [sharedApplication currentUserNotificationSettings];
isRemoteNotificationsAllowed = (settings.types != UIUserNotificationTypeNone);
isRemoteNotificationsAllowed = [sharedApplication isRegisteredForRemoteNotifications];

MXLogDebug(@"[MXKAccountManager][Push] isPushAvailable: The user %@ remote notification", (isRemoteNotificationsAllowed ? @"allowed" : @"denied"));
}
Expand Down