با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این سند نحوه شروع توسعه با Nearby Messages API در iOS را توضیح می دهد.
مرحله 1: آخرین نسخه Xcode را دریافت کنید
برای ساختن یک پروژه با استفاده از Google Nearby Messages API برای iOS، به نسخه 6.3 یا جدیدتر Xcode نیاز دارید.
مرحله 2: CocoaPods را دریافت کنید
Google Nearby Messages API برای iOS به عنوان یک CocoaPods در دسترس است. CocoaPods یک مدیر وابستگی منبع باز برای پروژه های Swift و Objective-C Cocoa است.
اگر از قبل ابزار CocoaPods را ندارید، با اجرای دستور زیر از ترمینال، آن را روی OS X نصب کنید. برای جزئیات، به راهنمای شروع به کار CocoaPods مراجعه کنید.
$sudogeminstallcocoapods
مرحله 3: API را با استفاده از CocoaPods نصب کنید
یک Podfile برای Google Nearby Messages API برای iOS ایجاد کنید و از آن برای نصب API و وابستگی های آن استفاده کنید.
اگر هنوز پروژه Xcode ندارید، اکنون یکی را ایجاد کرده و آن را در دستگاه محلی خود ذخیره کنید. (اگر در توسعه iOS تازه کار هستید، یک برنامه Single View ایجاد کنید و مطمئن شوید که Use Automatic Reference Counting روشن است.)
یک فایل به نام Podfile در دایرکتوری پروژه خود ایجاد کنید. این فایل وابستگی های پروژه شما را تعریف می کند.
Podfile را ویرایش کنید و وابستگی های خود را اضافه کنید. در اینجا یک Podspec ساده، شامل نام pod مورد نیاز برای Google Nearby Messages API برای iOS آمده است:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
pod 'NearbyMessages'
Podfile ذخیره کنید.
یک ترمینال را باز کنید و به دایرکتوری حاوی Podfile بروید:
$ سی دی
دستور pod install اجرا کنید. این API های مشخص شده در Podspec را به همراه وابستگی هایی که ممکن است داشته باشند نصب می کند.
$ pod نصب کنید
Xcode را ببندید و سپس فایل .xcworkspace پروژه خود را باز کنید (دوبار کلیک کنید) تا Xcode راه اندازی شود. از این زمان به بعد باید از فایل .xcworkspace برای باز کردن پروژه استفاده کنید.
مرحله 4: ایجاد یک هدر پل زدن (فقط Swift)
اگر پروژه خود را با استفاده از سوئیفت ایجاد کرده اید، باید یک هدر پل زدن به پروژه خود اضافه کنید تا بتواند از کتابخانه های نصب شده توسط فایل پاد استفاده کند. این مراحل را برای افزودن یک هدر پل زدن انجام دهید:
در همان فهرستی که فایل .xcworkspace پروژه شما قرار دارد، یک فایل هدر جدید اضافه کنید (آن را هر چه دوست دارید نامگذاری کنید و از پسوند نام فایل ".h" استفاده کنید).
کد زیر را در فایلی که ایجاد کردید قرار دهید: #import <GNSMessages.h> .
فایل را ذخیره کنید.
در پنجره سمت چپ ویرایشگر پروژه، پروژه اصلی را انتخاب کنید.
روی Build Settings در بالای ویرایشگر ساخت کلیک کنید.
در Build Settings، به "Swift Compiler - Code Generation" بروید ("Swift Compiler" را در کادر جستجو تایپ کنید تا سریع آن را پیدا کنید).
برای گسترش بخش Objective-C Bridging Header روی فلش کلیک کنید.
در قسمت Debug and Release ، مسیر را به فایل هدری که ایجاد کردید اضافه کنید.
پروژه را بسازید تا تغییرات اعمال شود.
مرحله 5: یک حساب Google دریافت کنید
برای استفاده از Nearby Messages API، به یک حساب Google نیاز دارید. اگر قبلاً یک حساب کاربری دارید، پس همه چیز آماده است. همچنین ممکن است یک حساب Google جداگانه برای اهداف آزمایشی بخواهید.
مرحله 6: یک کلید API دریافت کنید
برای فعال کردن Google Nearby Messages API برای iOS و دریافت یک کلید API، این مراحل را انجام دهید:
پروژه ای را برای ثبت درخواست خود ایجاد یا انتخاب کنید.
برای فعال کردن API روی Continue کلیک کنید.
در صفحه Credentials ، یک کلید iOS جدید ایجاد کنید (و API Credentials را تنظیم کنید). توجه: اگر یک کلید iOS موجود دارید، میتوانید از آن کلید استفاده کنید.
در گفتگوی به دست آمده، شناسه بسته نرم افزاری خود را وارد کنید. به عنوان مثال:
com.example.nearbyexample
کلید جدید iOS API شما در لیست کلیدهای API پروژه شما ظاهر می شود. یک کلید API رشته ای از کاراکترها است، چیزی شبیه به این:
AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0
برای جلوگیری از سرقت سهمیه، کلید API خود را با رعایت این بهترین شیوهها ایمن کنید.
مرحله 7: یک شی مدیر پیام ایجاد کنید
شیء مدیر پیام به شما امکان می دهد منتشر کنید و مشترک شوید. تبادل پیام احراز هویت نشده است، بنابراین باید کلید API را که در مرحله قبل ایجاد کردهاید، ارائه دهید.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe Nearby Messages API is deprecated and will stop working in December 2023, with users encouraged to migrate to Nearby Connections.\u003c/p\u003e\n"],["\u003cp\u003eDeveloping with the Nearby Messages API on iOS requires Xcode version 6.3 or later and the use of CocoaPods for dependency management.\u003c/p\u003e\n"],["\u003cp\u003eInstallation of the API is done via creating and editing a \u003ccode\u003ePodfile\u003c/code\u003e with a simple \u003ccode\u003epod install\u003c/code\u003e command in the terminal.\u003c/p\u003e\n"],["\u003cp\u003eSwift projects additionally require the creation of a bridging header file, referencing GNSMessages.h, and specifying the path to this in the project's build settings.\u003c/p\u003e\n"],["\u003cp\u003eUsing the API requires a Google account and an API key, which is generated in the Google Developers Console by enabling the Nearby Messages API.\u003c/p\u003e\n"]]],["The guide outlines the process for developing with the deprecated Nearby Messages API on iOS. Key actions include: installing Xcode (v6.3+), setting up CocoaPods for dependency management, creating a `Podfile` to install the 'NearbyMessages' pod, and adding a bridging header for Swift projects. A Google account and an iOS API key are needed, generated via the Google Developers Console using the app's bundle identifier. Finally, a message manager object is created using the API key to enable publishing and subscribing.\n"],null,["# Get Started\n\n| **Warning:** Nearby Messages is deprecated and will stop working as of December 2023. Please navigate to [Nearby Connections](//developers.google.com/nearby/connections/overview) for further support or [Migration Guideline](//developers.google.com/nearby/messages/ios/migrate-to-nc) on how to migrate existing Nearby Messages usage to Nearby Connections.\n\nThis document explains how to start developing with the Nearby Messages API on\niOS.\n\nStep 1: Get the latest version of Xcode\n---------------------------------------\n\nTo build a project using the Google Nearby Messages API for iOS, you need\n**version 6.3** or later of [Xcode](https://developer.apple.com/xcode/).\n\nStep 2: Get CocoaPods\n---------------------\n\nThe Google Nearby Messages API for iOS is available as a\n[CocoaPods](https://cocoapods.org/) pod. CocoaPods is an open source dependency\nmanager for Swift and Objective-C Cocoa projects.\n\nIf you don't already have the CocoaPods tool, install it on OS X by running the\nfollowing command from the terminal. For details, see the [CocoaPods Getting\nStarted guide](https://guides.cocoapods.org/using/getting-started.html). \n\n $ sudo gem install cocoapods\n\nStep 3: Install the API using CocoaPods\n---------------------------------------\n\nCreate a `Podfile` for the Google Nearby Messages API for iOS and use it to\ninstall the API and its dependencies.\n\n- If you don't have an Xcode project yet, create one now and save it to your local machine. (If you're new to iOS development, create a Single View Application, and ensure that Use Automatic Reference Counting is turned on.)\n- Create a file named `Podfile` in your project directory. This file defines your project's dependencies.\n- Edit the `Podfile` and add your dependencies. Here is a simple Podspec,\n including the name of the pod you need for the Google Nearby Messages API for\n iOS:\n\n ```text\n source 'https://github.com/CocoaPods/Specs.git'\n platform :ios, '7.0'\n pod 'NearbyMessages'\n ```\n\n \u003cbr /\u003e\n\n- Save the `Podfile`.\n\n- Open a terminal and go to the directory containing the `Podfile`:\n\n $ cd\n- Run the `pod install` command. This will install the APIs specified in the\n Podspec, along with any dependencies they may have.\n\n $ pod install\n- Close Xcode, and then open (double-click) your project's `.xcworkspace` file\n to launch Xcode. From this time onwards, you must use the `.xcworkspace` file to\n open the project.\n\nStep 4: Create a bridging header (Swift only)\n---------------------------------------------\n\nIf you created your project using Swift, you must add a bridging header to your\nproject so that it can use the libraries that were installed by the pod file.\nTake these steps to add a bridging header:\n\n1. In the same directory as your project's `.xcworkspace` file, add a new header file (name it whatever you like and use a filename extension of \".h\").\n2. Paste the following code into the file you created: `#import \u003cGNSMessages.h\u003e`.\n3. Save the file.\n4. In the project editor left pane, select the main project.\n5. Click **Build Settings** at the top of the build editor.\n6. In Build Settings, navigate to \"Swift Compiler - Code Generation\" (type \"Swift Compiler\" into the search box to locate it quickly).\n7. Click the arrow to expand the **Objective-C Bridging Header** section.\n8. Under **Debug** and **Release**, add the path to the header file you created.\n9. Build the project to make the changes take effect.\n\nStep 5: Get a Google account\n----------------------------\n\nTo use the Nearby Messages APIs, you need a [Google Account](//www.google.com/accounts/NewAccount).\nIf you already have an account, then you're all set. You may also want a\nseparate Google Account for testing purposes.\n\nStep 6: Get an API key\n----------------------\n\nTake these steps to enable the Google Nearby Messages API for iOS and get an\nAPI key:\n\n1. Go to the [Google Developers Console](https://console.developers.google.com/flows/enableapi?apiid=copresence&keyType=CLIENT_SIDE_IOS&reusekey=true).\n2. Create or select a project to register your application with.\n3. Click **Continue** to Enable the API.\n4. On the **Credentials** page, create a new **iOS key** (and set the API Credentials). \n Note: If you have an existing **iOS key**, you may use that key.\n5. In the resulting dialog, enter your app's bundle identifier. For example: \n\n ```\n com.example.nearbyexample\n ```\n6. Your new iOS API key appears in the list of API keys for your project. An API key is a string of characters, something like this: \n\n ```\n AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0\n ```\n7. To prevent quota theft, secure your API key following these [best practices](/console/help/console#apikeybestpractices).\n\n| **Note:** If you are also developing an Android app, or using the Proximity Beacon REST API, make sure you generate all respective API keys within the same Google Developers Console project. For more information, see the [Getting Started guide for Android](/nearby/messages/android/get-started), and [Get Started with the REST API](/beacons/proximity/get-started).\n\nStep 7: Create a message manager object\n---------------------------------------\n\nThe message manager object lets you publish and subscribe. Message exchange is\nunauthenticated, so you must supply the API key you created in the previous\nstep.\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n #import \u003cGNSMessages.h\u003e\n\n GNSMessageManager *messageManager =\n [[GNSMessageManager alloc] initWithAPIKey:@\"API_KEY\"];\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let messageManager = GNSMessageManager(APIKey: \"API_KEY\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]