GNSMessage 类
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
消息是在附近设备之间传送的已发布对象。
消息只能在共享相同 Apiary 开发者控制台 ID 的应用之间递送。请参阅 https://code.google.com/apis/console/
消息还有一个类型,用于将已发布的消息与订阅进行匹配。
- 另请参阅
- GNSMessageManager以详细了解发布内容和订阅。
此类继承 NSObject。
|
((unavailable("Use
+messageWithContent.") | - __attribute__ |
|
+ (instancetype) messageWithContent: |
|
(NSData *) |
content |
|
- (NSString*) messageNamespace |
|
readnonatomiccopy |
消息类型的命名空间。
空字符串是默认命名空间,每个应用(或共享 Google Developer Console 项目的应用)专用。请注意,目前,只有信标附件的命名空间不是默认命名空间。
消息的类型。
长度不得超过 kGNSMessagemaximumLength Unicode 字符。如果尝试使用更长的类型,会导致库在已启用断言的情况下进行断言,而在已停用断言时无法发布消息。
消息的内容。
数据格式因应用而异,必须获得数据的所有发布者和订阅者的同意。长度不得超过 kGNSMessagemaximumContentSize。如果尝试使用大于此大小的对象,库会在已启用断言的情况下进行断言,而在已停用断言的情况下无法发布消息。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-13。
[null,null,["最后更新时间 (UTC):2025-08-13。"],[[["\u003cp\u003eThe \u003ccode\u003eGNSMessage\u003c/code\u003e class facilitates communication between nearby devices by publishing and delivering messages between apps sharing the same Apiary Dev Console ID.\u003c/p\u003e\n"],["\u003cp\u003eMessages have a content and type, allowing applications to filter and process relevant messages; content is application-specific, while type enables matching with subscriptions.\u003c/p\u003e\n"],["\u003cp\u003eYou can create messages using class methods \u003ccode\u003emessageWithContent:\u003c/code\u003e for the default type, or \u003ccode\u003emessageWithContent:type:\u003c/code\u003e to specify a custom type.\u003c/p\u003e\n"],["\u003cp\u003eMessages are restricted in size: type cannot exceed \u003ccode\u003ekGNSMessageMaximumLength\u003c/code\u003e Unicode characters and content cannot be larger than \u003ccode\u003ekGNSMessageMaximumContentSize\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe message namespace, primarily used for beacon attachments, defaults to an empty string and is private to apps or apps sharing a Google Developer Console project.\u003c/p\u003e\n"]]],["The GNSMessage class manages messages delivered between nearby devices within the same app or apps sharing an ID. Messages have content, a type, and a namespace. Key actions include creating messages using class methods: `messageWithContent:` for the default type and `messageWithContent:type:` for a specified type. Properties include `messageNamespace`, `type`, and `content`, which hold the message's namespace, type, and data, respectively. Message size and type length have limits.\n"],null,["# GNSMessage Class\n\n[Instance Methods](#pub-methods) \\| [Class Methods](#pub-static-methods) \\| [Properties](#properties) \nGNSMessage Class Reference \n\nOverview\n--------\n\nA message is a published object that is delivered between nearby devices.\n\nMessages are delivered only between apps sharing the same Apiary Dev Console ID. See \u003chttps://code.google.com/apis/console/\u003e\n\nA message also has a type, which is used to match a published message with subscriptions.\n\nSee also\n: [GNSMessageManager](/nearby/messages/ios/reference/interface_g_n_s_message_manager \"The message manager lets you create publications and subscriptions. \") for more information about publications and subscriptions.\n\nInherits NSObject.\n\n|-------------------------------------------|---------------------|\n| Instance Method Summary ----------------------- ||\n| ((unavailable(\"Use +messageWithContent.\") | - **__attribute__** |\n| ||\n\n|----------------|------------------------------------------------------------------------------------------------------------------------|\n| Class Method Summary -------------------- ||\n| (instancetype) | + [messageWithContent:](/nearby/messages/ios/reference/interface_g_n_s_message#a11c95fc8aa716759a95b46ac2d9658b5) |\n| | Message with the default type. [More...](#a11c95fc8aa716759a95b46ac2d9658b5) |\n| ||\n| (instancetype) | + [messageWithContent:type:](/nearby/messages/ios/reference/interface_g_n_s_message#a86840561e1ebbcb98ad209adc110fb74) |\n| | Message with the specified type. [More...](#a86840561e1ebbcb98ad209adc110fb74) |\n| ||\n\n|-------------|--------------------------------------------------------------------------------------------------------------|\n| Property Summary ---------------- ||\n| NSString \\* | [messageNamespace](/nearby/messages/ios/reference/interface_g_n_s_message#aad0830d118becf213310c83b279bf0a6) |\n| | The namespace of the message type. [More...](#aad0830d118becf213310c83b279bf0a6) |\n| ||\n| NSString \\* | [type](/nearby/messages/ios/reference/interface_g_n_s_message#a20d9593b44edfbfa78e4d4416d8a2a1c) |\n| | The type of the message. [More...](#a20d9593b44edfbfa78e4d4416d8a2a1c) |\n| ||\n| NSData \\* | [content](/nearby/messages/ios/reference/interface_g_n_s_message#abd1454b18947ac01b56ac926ff9e6626) |\n| | The content of the message. [More...](#abd1454b18947ac01b56ac926ff9e6626) |\n| ||\n\nMethod Detail\n-------------\n\n|--------------------------------------|---|-------------|-----------|---|\n| + (instancetype) messageWithContent: | | (NSData \\*) | *content* | |\n\nMessage with the default type.\n\nSee also\n: [GNSMessage.content](/nearby/messages/ios/reference/interface_g_n_s_message#abd1454b18947ac01b56ac926ff9e6626 \"The content of the message. \") for more information about the [content](/nearby/messages/ios/reference/interface_g_n_s_message#abd1454b18947ac01b56ac926ff9e6626 \"The content of the message. \"). \n\n|----------------------------------------------------------------------------------------------------------------------------------|---|---------------|-----------|\n| + (instancetype) [messageWithContent:](/nearby/messages/ios/reference/interface_g_n_s_message#a11c95fc8aa716759a95b46ac2d9658b5) | | (NSData \\*) | *content* |\n| type: | | (NSString \\*) | *type* |\n| | | | |\n\nMessage with the specified type.\n\nSee also\n: [GNSMessage.content](/nearby/messages/ios/reference/interface_g_n_s_message#abd1454b18947ac01b56ac926ff9e6626 \"The content of the message. \") for more information about the [content](/nearby/messages/ios/reference/interface_g_n_s_message#abd1454b18947ac01b56ac926ff9e6626 \"The content of the message. \").\n:\n [GNSMessage.type](/nearby/messages/ios/reference/interface_g_n_s_message#a20d9593b44edfbfa78e4d4416d8a2a1c \"The type of the message. \") for more information about the [type](/nearby/messages/ios/reference/interface_g_n_s_message#a20d9593b44edfbfa78e4d4416d8a2a1c \"The type of the message. \").\n\nProperty Detail\n---------------\n\n|-------------------------------------------------------------------------|-------------------|\n| |---------------------------------| | - (NSString\\*) messageNamespace | | readnonatomiccopy |\n\nThe namespace of the message type.\n\nThe empty string is the default namespace, and is private to each app (or apps sharing a Google Developer Console project). Note that currently, only beacon attachments will have a namespace other than the default. \n\n|-------------------------------------------------|-------------------|\n| |---------------------| | - (NSString\\*) type | | readnonatomiccopy |\n\nThe type of the message.\n\nCannot be longer than kGNSMessageMaximumLength Unicode characters. Attempting to use a longer type will cause the library to assert if assertions are enabled and not publish the message if assertions are disabled. \n\n|---------------------------------------------------|-------------------|\n| |----------------------| | - (NSData\\*) content | | readnonatomiccopy |\n\nThe content of the message.\n\nThe format of the data is application-specific, and must be agreed upon by all publishers and subscribers of the data. Cannot be longer than kGNSMessageMaximumContentSize. Attempting to use an object larger than this will cause the library to assert if assertions are enabled and not publish the message if assertions are disabled."]]