This application builds upon PubNub's iOS Chat Components Application by adding Apple push notifications. You'll be using PubNub to construct and send mobile push notification payloads to the Apple Push Notification Service (APNs) to deliver the notifications to your device. A detailed tutorial is available for a step-by-step guide.
- Pre-built UI Component that renders and handles displaying the chat room.
- Send messages to other users in the chat room.
- Receive messages from other users in the chat room.
- See past messages from other users in the chat room, even if the current user is offline.
- See message reactions from users in the debug console and interact with the iOS app in real-time.
- Receive and display mobile push notifications, regardless of application state
- Xcode (The latest stable version)
- Git
- Apple Developer Account with access to the Apple Developer Program. You'll need to be enrolled in this program in order to access services that allow your application to receive mobile push notifications from APNs. Please note that this is a paid program.
- Physical iOS Device (iPhone, iPad, iPod Touch, etc). Simulated devices in Xcode cannot be registered in APNs, and thus cannot receive a device token, which is necessary when sending mobile push notifications across the PubNub network.
- PubNub Account (Free)
- Sign in to your PubNub Dashboard. You are now in the Admin Portal.
- Go to Apps using the left-hand side navigation.
- Click the Create New App button in the top-right of the Portal.
- Give your app a name.
- Click Create.
- Click your new app to open its settings.
- When you create a new app, the first set of keys are generated automatically. However, a single app can have as many keysets as you like. PubNub recommends that you create separate keysets for production and test environments.
- Click on the keyset.
- Enable four features for the keyset to be able to connect to the PubNub Network: Presence, Message Persistence, Stream Controller, and Mobile Push Notifications.
- Enable Presence by clicking on the slider to turn it on. A pop-up will require that you enter in “ENABLE”. Enter in “ENABLE” in all caps and then press the “Enable” button. You can leave the default settings.
- Enable Message Persistence by clicking on the slider to turn it on. You can leave the default settings.
- Enable Stream Controller by clicking on the slider to turn it on if it is already not enabled. You can leave the default settings.
- Enable Mobile Push Notifications by clicking on the slider to turn it on. In the Apple Push Credentials section, you need to upload the APNs Authentication Token file. This file is obtained from your Apple Developer Account when you create your Key in Certificates, Identifiers & Profiles -> Keys -> Register a New Key -> Give the key a name and enable APNs -> Click continue, register, and then download. If you no longer have access to the token file, you'll need to register and create a new key. Upload the token file. Enter in the Team ID and Auth Key ID fields found in the following locations in your Apple Developer Account. Team ID: Overview -> Membership -> Team ID; Auth Key ID: Overview -> Certificates, IDs & Profiles -> Keys -> Key ID in View Key Details.
- Click on save changes.
- Copy the Publish and Subscribe Keys to a text editor.
-
Clone the GitHub repository.
git clone https://github.com/PubNubDevelopers/ios-push-notifications-tutorial.git
-
Open your project in Xcode. Sign in using your developer account if you have not done so.
-
In the project navigator, click on the project file. In the Targets section, click on your project.
-
In the General tab, enter a unique Bundle Identifier by appending something like -push at the end of the ID. APNs identifies your application in a provisioning profile by combining a Team ID (generated by Apple) and your Bundle Identifier as an explicit App ID to be able to use certain capabilities, including receiving mobile push notifications for your application.
-
Click on the Signing & Capabilities tab.
-
Ensure that the checkbox for "Automatically manage signing" is checked.
-
In the Signing section, ensure that your developer account is selected in the Team drop-down.
-
Ensure the Bundle Identifier is the same as that in the General tab.
-
Add Mobile Push Notification support to your application by clicking on the + symbol, search for "push notifications", and then double click the Capability to add to your application.
-
This application utilizes the PubNub Swift SDK and Chat Components for iOS libraries. Add these packages by clicking on File -> Add Packages and entering the following package URL: https://github.com/pubnub/chat-components-ios.
-
Navigate to AppDelegate.swift. At the top of the file, ensure that the PubNub library necessary to be able to use the PubNub Swift SDK is already imported. Add the UserNotifications library to be able to use mobile push notifications in your project.
-
Connect and register physical Apple Device.
-
Build and run app by pressing the play button.
-
Send and receive messages, and view past messages from other users.
-
Generate new users each time the application is restarted.
-
Receive messages in real-time by interacting with the debug console.
-
Incorporate push functionality.
- Project homepage: https://pubnub.com
- Tutorial Link: https://www.pubnub.com/tutorials/mobile-push-notifications-ios-swift/
- Swift Weather Application integrated with chat using PubNub's Chat Components for iOS: https://github.com/PubNubDevelopers/Swift-Weather-Chat/
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.