GNSSubscriptionParams 类
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
订阅的可选参数。
请参阅下面的属性声明,了解每个参数的说明。
此类继承 NSObject。
- (GNSDeviceTypes) deviceTypesToDiscover |
|
readwritenonatomicassign |
要发现的设备类型。
默认值为 kGNSDeviceUsingNearby
。
- (NSString*) messageNamespace |
|
readwritenonatomicassign |
要匹配的消息命名空间。
空字符串是默认命名空间,每个应用(或共享 Google Developer Console 项目的应用)专用。
要匹配的消息类型。不得为 nil。空字符串是默认类型。
- (GNSOperationStatusHandler) statusHandler |
|
readwritenonatomiccopy |
订阅状态的处理程序。
它可用于跟踪新创建的订阅的状态。
- (GNSPermissionRequestHandler) permissionRequestHandler |
|
readwritenonatomiccopy |
用于请求用户使用“附近”功能的权限的处理程序。
此处理程序会覆盖“附近”功能使用的默认对话框;如果您提供此处理程序,“附近”功能将不会显示其权限对话框。
在请求处理程序中,您应请求用户授予执行需要使用“附近”功能的任务的权限,并说明使用该功能的原因。当用户表示或拒绝后,您必须调用传入请求处理程序的代码块。如果您将 YES
传递到代码块中,则表示用户已同意启用“附近”功能。如果您传递 NO
,则表示用户未同意;只有在征得用户同意后,您的发布内容和订阅才能正常运行。
处理程序还可用作 iOS 权限对话框的“预检”方法。您可以用它来解释为什么需要用户同意 iOS 权限,您的应用才能执行其“附近分享”相关功能。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-13。
[null,null,["最后更新时间 (UTC):2025-08-13。"],[[["\u003cp\u003e\u003ccode\u003eGNSSubscriptionParams\u003c/code\u003e provides optional parameters for customizing Nearby Messages subscriptions.\u003c/p\u003e\n"],["\u003cp\u003eParameters include device types, message namespace and type, discovery strategies, and handlers for status and permissions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003estrategy\u003c/code\u003e property controls discovery of Nearby devices, while \u003ccode\u003ebeaconStrategy\u003c/code\u003e is for beacon scanning.\u003c/p\u003e\n"],["\u003cp\u003eYou can define handlers to monitor subscription status and manage user permission requests for Nearby.\u003c/p\u003e\n"],["\u003cp\u003eDefault values are provided for most parameters, simplifying basic subscription setup.\u003c/p\u003e\n"]]],[],null,["# GNSSubscriptionParams Class\n\n[Properties](#properties) \nGNSSubscriptionParams Class Reference \n\nOverview\n--------\n\nOptional parameters for a subscription.\n\nSee the property declarations below for explanations of each parameter.\n\nInherits NSObject.\n\n|----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| Property Summary ---------------- ||\n| GNSDeviceTypes | [deviceTypesToDiscover](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#aa972c219c7211e4a7c5fa785d0b11274) |\n| | The types of devices to discover. [More...](#aa972c219c7211e4a7c5fa785d0b11274) |\n| ||\n| NSString \\* | [messageNamespace](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#a70e97d712c8bc53a7f9076055a91256a) |\n| | The message namespace to match. [More...](#a70e97d712c8bc53a7f9076055a91256a) |\n| ||\n| NSString \\* | [type](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#a86a3f486660ee32e5824b03fcef62533) |\n| | The message type to match. Must not be nil. The empty string is the default type. [More...](#a86a3f486660ee32e5824b03fcef62533) |\n| ||\n| [GNSStrategy](/nearby/messages/ios/reference/interface_g_n_s_strategy) \\* | [strategy](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#a20f64cb0cfd8890f640536dfb586e814) |\n| | The strategy to use for discovering Nearby devices (non-beacons). [More...](#a20f64cb0cfd8890f640536dfb586e814) |\n| ||\n| [GNSBeaconStrategy](/nearby/messages/ios/reference/interface_g_n_s_beacon_strategy) \\* | [beaconStrategy](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#a2a2c2aecb81fef6ff47fc4204110f6da) |\n| | The strategy to use for beacon scanning. [More...](#a2a2c2aecb81fef6ff47fc4204110f6da) |\n| ||\n| GNSOperationStatusHandler | [statusHandler](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#afb1a6c67329810c58745f2f4625240cc) |\n| | A handler for subscription status. [More...](#afb1a6c67329810c58745f2f4625240cc) |\n| ||\n| GNSPermissionRequestHandler | [permissionRequestHandler](/nearby/messages/ios/reference/interface_g_n_s_subscription_params#ac037a18632caddcdb730bdb2a0f9c1b1) |\n| | A handler for requesting user permission to use Nearby. [More...](#ac037a18632caddcdb730bdb2a0f9c1b1) |\n| ||\n\nProperty Detail\n---------------\n\n|-------------------------------------------------------------------------------------------|--------------------------|\n| |------------------------------------------| | - (GNSDeviceTypes) deviceTypesToDiscover | | readwritenonatomicassign |\n\nThe types of devices to discover.\n\nThe default is `kGNSDeviceUsingNearby`. \n\n|-------------------------------------------------------------------------|--------------------------|\n| |---------------------------------| | - (NSString\\*) messageNamespace | | readwritenonatomicassign |\n\nThe message namespace to match.\n\nThe empty string is the default namespace, and is private to each app (or apps sharing a Google Developer Console project). \n\n|-------------------------------------------------|--------------------------|\n| |---------------------| | - (NSString\\*) type | | readwritenonatomicassign |\n\nThe message type to match. Must not be nil. The empty string is the default type. \n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|\n| |---------------------------------------------------------------------------------------| | - ([GNSStrategy](/nearby/messages/ios/reference/interface_g_n_s_strategy)\\*) strategy | | readwritenonatomicassign |\n\nThe strategy to use for discovering Nearby devices (non-beacons). \n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|\n| |----------------------------------------------------------------------------------------------------------| | - ([GNSBeaconStrategy](/nearby/messages/ios/reference/interface_g_n_s_beacon_strategy)\\*) beaconStrategy | | readwritenonatomicassign |\n\nThe strategy to use for beacon scanning. \n\n|-------------------------------------------------------------------------------------------------|------------------------|\n| |---------------------------------------------| | - (GNSOperationStatusHandler) statusHandler | | readwritenonatomiccopy |\n\nA handler for subscription status.\n\nIt can be used for tracking the status of a newly created subscription. \n\n|---------------------------------------------------------------------------------------------------------------------------|------------------------|\n| |----------------------------------------------------------| | - (GNSPermissionRequestHandler) permissionRequestHandler | | readwritenonatomiccopy |\n\nA handler for requesting user permission to use Nearby.\n\nThis handler overrides the default dialog used by Nearby; if you supply this handler, Nearby will not show its permission dialog.\n\nIn your request handler, you should request the user's permission to perform the task that requires the use of Nearby, explaining why it's being used. When the user has given or denied consent, you must call the block that's passed into your request handler. If you pass `YES` into the block, it means the user has consented to allow Nearby to function. If you pass `NO`, it means the user has not consented; your publications and subscriptions will not work until consent has been given.\n\nThe handler can also be used as a method of \"preflighting\" for the iOS permission dialogs. You can use it to explain why the user is expected to consent to the iOS permissions before your app can perform its Nearby related functions."]]