AI-generated Key Takeaways
-
The
GNSPermission
class manages the Nearby permission state for your app, enabling features like publications and subscriptions. -
Users must grant Nearby permission for these features to function; the system automatically requests this permission when needed.
-
You can track and react to permission state changes using a
GNSPermission
object with a change handler. -
Provide a UI element, like a toggle switch, allowing users to control the Nearby permission and update the state using
isGranted
andsetGranted
methods. -
The initial permission request is automatic, but subsequent requests depend on the user's previous choice and your app's UI for toggling the permission.
Overview
This class lets you manage the Nearby permission state for the app on the current device.
The user must grant permission before publications and subscriptions will work. The first time the application creates a publication or subscription, the Nearby permission dialog is automatically displayed, giving the user the opportunity to opt in. If the user denies, an alert will be displayed each time a publication or subscription is subsequently created, giving them another chance to opt in.
It is recommended that your app provide the user a method for switching the permission on or off; for instance, by using a toggle switch in a settings page. When the user toggles it, the app should call the isGranted
and setGranted
methods below to toggle the permission state.
To track the permission state, create a GNSPermission
object and pass in a changed handler. The handler will be called whenever the permission state is changed, allowing your app's UI to be kept in sync with the current state.
Inherits NSObject.
Instance Method Summary | |
(instancetype) | - initWithChangedHandler: |
Initializes the permission object with a handler that is called whenever the permission state changes. More... | |
Class Method Summary | |
(BOOL) | + isGranted |
Whether Nearby permission is currently granted for the app on this device. More... | |
(void) | + setGranted: |
Changes the Nearby permission state. More... | |
Method Detail
- (instancetype) initWithChangedHandler: | (GNSPermissionHandler) | changedHandler |
Initializes the permission object with a handler that is called whenever the permission state changes.
The handler lets the app keep its UI in sync with the permission state. The handler is not called until the user has approved or denied permission.
- Parameters
-
handler The permission granted handler
+ (BOOL) isGranted |
Whether Nearby permission is currently granted for the app on this device.
YES means the user has granted Nearby permission, and NO means the user has denied permission. If permission has not been granted, publications and subscriptions will not work.
+ (void) setGranted: | (BOOL) | granted |
Changes the Nearby permission state.
This should be called only in response to the user action of changing the permission state.