Skip to content

Commit

Permalink
Always request permission instead of skipping if already granted (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski authored Sep 23, 2024
1 parent d44016f commit ee60b94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
11 changes: 3 additions & 8 deletions Airship/AirshipCore/Source/PermissionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,9 @@ public final class AirshipPermissionsManager: NSObject, @unchecked Sendable {
}

let startingStatus = await delegate.checkPermissionStatus()
var endStatus: AirshipPermissionStatus = .notDetermined

switch(startingStatus) {
case .granted:
endStatus = .granted
case .notDetermined:
endStatus = await delegate.requestPermission()
case .denied:
var endStatus: AirshipPermissionStatus = await delegate.requestPermission()

if startingStatus == .denied, endStatus == .denied {
switch fallback {
case .none:
endStatus = .denied
Expand Down
10 changes: 5 additions & 5 deletions Airship/AirshipCore/Tests/PermissionsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PermissionsManagerTests: XCTestCase {
let status = await self.permissionsManager.requestPermission(.location)

XCTAssertEqual(AirshipPermissionStatus.denied, status)
XCTAssertFalse(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.checkCalled)
}

Expand All @@ -117,7 +117,7 @@ class PermissionsManagerTests: XCTestCase {
let status = await self.permissionsManager.requestPermission(.location)

XCTAssertEqual(AirshipPermissionStatus.granted, status)
XCTAssertFalse(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.checkCalled)
}

Expand All @@ -131,7 +131,7 @@ class PermissionsManagerTests: XCTestCase {

_ = await self.permissionsManager.requestPermission(.location, enableAirshipUsageOnGrant: false, fallback: .systemSettings)

XCTAssertFalse(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.checkCalled)
XCTAssertEqual(systemSettingsNavigator.permissionOpens, [.location])
}
Expand All @@ -148,7 +148,7 @@ class PermissionsManagerTests: XCTestCase {

_ = await self.permissionsManager.requestPermission(.location, enableAirshipUsageOnGrant: false, fallback: .systemSettings)

XCTAssertFalse(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.checkCalled)
XCTAssertEqual(systemSettingsNavigator.permissionOpens, [.location])
}
Expand All @@ -170,7 +170,7 @@ class PermissionsManagerTests: XCTestCase {
)

XCTAssertEqual(AirshipPermissionStatus.granted, status.endStatus)
XCTAssertFalse(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.requestCalled)
XCTAssertTrue(self.delegate.checkCalled)
}

Expand Down

0 comments on commit ee60b94

Please sign in to comment.