[MUSIC PLAYING]
LAURENCE MORONEY: What's up, everybody?
Laurence here from the Firebase team.
And welcome to another episode of "Firecasts."
On today's episode, I'm going to show you
how you can receive messages using
Firebase Notifications on iOS.
Then you can be up and running with this feature
in just a few minutes.
So let's get started.
The first thing that you'll need to do
is to make sure that your app is ready for Firebase.
Let's create a single view application.
We'll call it iOS Firebase Notification 1.
I'll just put it on my Desktop.
Before doing anything else, I need to close the project
and open a terminal.
>From here, I change to my Project Directory,
and I do a pod in it.
Once that's complete, I'll have a pod file that I can edit.
In the pod file, I add the Firebase Core and Firebase
Messaging pods.
I then run Pod Install, and the SDK
will be added to my project, creating a workspace.
>From now on, I just open the workspace.
In Firebase Console, you need to link your iOS app
with a project.
You do this by clicking Add App within your project.
Select Add Firebase to your iOS app.
You then specify the bundle identifier
and optionally the App Store ID.
I had done one previously.
So I'll just cancel out.
To download the plist, select Manage.
You'll then see a button to download it.
This will give you a Google service info dot plist file.
You drag this to your project in Xcode,
and you're now ready to get coding.
Now that your app is ready for Firebase,
you're going to need to get an Apple Push Notifications
token, a certificate from that, and a Firebase project
to link it with.
Let's do that next.
You get your APNS certificate from the Apple Developer
Console.
Select Certificates, IDs, and Profiles.
If your app has been configured for APNS,
you'll see a certificate here.
Click to download your certificate file.
This can then be used to generate a dot p12.
For more details, see here.
Once you have your certificate, you
can upload it to the Firebase Console.
Select your project, pick your iOS app and select Manage.
Select the Cloud Messaging tab, then
select the Upload Certificate button and upload your p12.
Now that you've set everything up,
lets build a simple app that receives messages
from Firebase Notifications, and we
can send it some messages from the Firebase console.
The code to get remote notifications in iOS
is very straightforward.
To get a notification, do the following-- in your App
Delegates Did Finish Launching With Options, add this code.
This simply creates the settings for notifications
that you want to get and registers the app
to receive them.
It then initializes Firebase.
Next, you need to create a Did Receive Remote Notification
Handler.
This gets a User Info Object as a dictionary.
In that, there is a key called APS,
and this contains an alert value.
You just read this value to get the contents
of the notification.
Let's run it and see.
I'll add a breakpoint.
Then from Firebase Console, I'll create a new message.
I'll send this to my iOS app, and when I return to Xcode,
I can see that the breakpoint has been hit.
If I step through and look at the console output,
you can see that the message has been received successfully.
And that's it for this Firecast.
Please leave your questions in the comments below,
or reach out on Twitter or G+.
We'll be dropping new Firecasts every week.
So don't forget to hit that Subscribe button.
I'm Laurence Moroney, and thanks for watching.
[MUSIC PLAYING]