คลาส GNSMessage
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ข้อความคือออบเจ็กต์ที่เผยแพร่แล้วซึ่งรับส่งระหว่างอุปกรณ์ที่อยู่ใกล้เคียง
ระบบจะส่งข้อความระหว่างแอปที่แชร์รหัส Apiary Dev Console เดียวกันเท่านั้น โปรดดู https://code.google.com/apis/console/
นอกจากนี้ ข้อความยังมีประเภทซึ่งใช้เพื่อจับคู่ข้อความที่เผยแพร่แล้วกับการติดตาม
- ดูเพิ่มเติม
- GNSMessageManager สำหรับข้อมูลเพิ่มเติมเกี่ยวกับสื่อเผยแพร่และการสมัครใช้บริการ
รับค่า NSObject
|
((unavailable("Use
+messageWithContent.") | - __attribute__ |
|
+ (instancetype) messageWithContent: |
|
(NSData *) |
content |
|
- (NSString*) messageNamespace |
|
readnonatomiccopy |
เนมสเปซของประเภทข้อความ
สตริงว่างคือเนมสเปซเริ่มต้น และเป็นแบบส่วนตัวสำหรับแต่ละแอป (หรือแอปที่แชร์โปรเจ็กต์ Google Developer Console) โปรดทราบว่าขณะนี้เฉพาะไฟล์แนบบีคอนเท่านั้นที่จะมีเนมสเปซที่ไม่ใช่ค่าเริ่มต้น
ประเภทของข้อความ
ต้องมีความยาวไม่เกินอักขระ Unicode kGNSMessageLimitLength การพยายามใช้ประเภทที่ยาวกว่าจะทำให้ไลบรารียืนยันว่ามีการเปิดใช้การยืนยันและไม่เผยแพร่ข้อความหากปิดใช้การยืนยัน
เนื้อหาของข้อความ
รูปแบบของข้อมูลดังกล่าวเป็นข้อมูลเฉพาะแอปพลิเคชัน และต้องมีการตกลงระหว่างผู้เผยแพร่และผู้สมัครใช้บริการข้อมูลทั้งหมด ต้องมีความยาวไม่เกิน kGNSMessageLimitContentSize การพยายามใช้ออบเจ็กต์ที่มีขนาดใหญ่กว่าจะทำให้ไลบรารียืนยันว่ามีการเปิดใช้การยืนยันและไม่เผยแพร่ข้อความหากปิดใช้การยืนยัน
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-13 UTC
[null,null,["อัปเดตล่าสุด 2025-08-13 UTC"],[[["\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."]]