加入我們的
郵寄清單,取得關於「鄰近分享」的最新消息和公告。
踏出第一步
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
安裝最新版 Xcode
如要在專案中使用 Nearby Connections,必須使用 Xcode 13.0 以上版本。
將 Nearby Connections 套件新增至專案
Xcode 內建套件管理工具。如要將 Nearby Connections 新增至 Xcode 專案,請依序選取「File」 >「Add Packages…」,然後搜尋 google/nearby
。然後按一下「新增套件」,等待程序完成 (可能需要幾分鐘)。
要求存取受保護的資源
「鄰近分享」需要存取藍牙和本機網路,才能發布、探索、建立連線及傳輸資料。在應用程式的 Info.plist
中,為每個必要資源提供使用說明。否則嘗試存取資源時會失敗,甚至可能導致應用程式異常終止。
必要使用說明鍵:
NSBluetoothAlwaysUsageDescription
NSLocalNetworkUsageDescription
除了使用情況說明鍵之外,還需要新增 NSBonjourServices
鍵,其中包含應用程式將瀏覽的服務類型清單。您必須新增的唯一服務類型,可透過應用程式服務 ID 的 SHA-256
雜湊前 12 個位元組產生。
您可以使用下列工具自動產生這個值:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-13 (世界標準時間)。
[null,null,["上次更新時間:2025-08-13 (世界標準時間)。"],[],[],null,["# Get started\n\nInstall the latest version of Xcode\n-----------------------------------\n\nTo use Nearby Connection in your project,\n[Xcode](https://developer.apple.com/xcode/) **13.0 or later** is required.\n\nAdd the Nearby Connections package to your project\n--------------------------------------------------\n\nXcode comes with a built-in package manager. To add Nearby Connections to your\nXcode project, select **File** \\\u003e **Add Packages...** and search for\n`google/nearby`. Then click **Add Package** and wait for the process to complete\n(this may take a few minutes).\n\nRequest access to protected resources\n-------------------------------------\n\nNearby Connections needs access to both Bluetooth and the local network to\nadvertise, discover, make connections, and transfer data. Provide a usage\ndescription for each resource needed, in your app's `Info.plist`. If you don't,\nattempts to access the resource will fail, and might even cause your app to\ncrash.\n\nRequired usage description keys:\n\n- `NSBluetoothAlwaysUsageDescription`\n- `NSLocalNetworkUsageDescription`\n\nIn addition to usage description keys, an `NSBonjourServices` key with a list of\nthe service types that will be browsed by the app, will also need to be added.\nThe only service type that must be added can be generated by taking the first 12\nbytes of the `SHA-256` hash of your app's service ID.\n\nYou can use the following tool to automatically generate this value for you: \nService ID\nGenerate\n\n```\n\n```"]]