Harnessing iOS to Create Magic in Your Apps

Session 310 WWDC 2013

Enrich the user experience in your apps by leveraging key iOS technologies in innovative ways. The Apple Store app engineering team will show you how they used Push Notifications, Core Location, Region Monitoring, and Bluetooth to create compelling product pickup and in-store experiences for their customers. Learn tips, tricks, and best practices, and see how you can also offer great experiences in your apps around event notifications, welcoming users to locations of interest, and enabling rich user interactions with their surroundings.

[ Applause ]

Good morning and welcome.

My name is Filip.

I'm the opening act for Bill Nye the Science Guy.

[ Laughter ]

Just kidding.

I lead the mobile apps engineering team at Apple and we build iOS apps just like you guys.

Our apps get built and submitted to the App Store.

They get approved and they get downloaded by users and they can get deleted too.

Of all the teams at Apple and of all the teams that have presented to you at WWDC this week, we're the most like you guys.

What we'd like to share with you today is some situations we come across in developing our apps.

These situations have given rise to opportunities where we could harness some key iOS technologies and create truly unique and compelling experiences for our users.

I'm going to show you the features that we built and the technologies behind them.

As I talk about our apps, I want you guys to think about your own apps and find some parallels.

And I know you can identify with a lot of the opportunities we'll see today and use these technologies in your own apps.

We'll talk also about tips, tricks, and best practices.

And finally, we'll end with a demo on iBeacons.

So let's get started.

First, I'd like to introduce the Apple Store app.

It's going to be the reference app for this presentation.

This is an app my team builds and you can download it from the App Store anytime, maybe even right now.

Let me see, who has the app on their phone?

Oh wow, good.

Who doesn't have it?

Who is downloading right now?

[ Laughter ]

A lot of you don't put up your hand.

Maybe you're shy.

If you're shy, you can come on the stage with me in front of all of you, you'll lose your shyness very fast.

OK. So, Apple Store app is a great way to learn about Apple products, to browse Apple products.

You can customize and buy.

You can also find out about Apple retail stores, what events are going on, maybe book an appointment like Genius Bar or pick up an order you made on the Apple Store app at the store.

And it's this key characteristic of the Apple Store app, this integration with the physical Apple Stores, and this by the way is the Upper West Side Store in New York.

It's going to be our reference store for the talk.

This intersection between the online with the Apple Store app and the physical with the Apple retail store gives rise to a lot of the opportunities we'll talk about today.

When I talk about our app in the store, I'd like you to think about your own situations.

So, maybe you have a Movie app and you want to think about movie theaters.

Maybe you have Dinner Reservation app and you want to think about restaurants.

Maybe you have a Travel app, you want to think about airports.

Amusement Park app, you want or Museum app, you want to think about museums and amusement parks or maybe your own Retail app and your own retail stores.

For those of you who don't have locations of interest in your app, don't worry, a lot of the technology we'll talk today will still be applicable for you guys.

So, this is my agenda slide, it's a timeline.

And it all centers around and we're going to use this timeline through the talk.

It all centers around the fact that there's an event.

OK, it can be anything.

Dinner is on tonight.

There's a movie playing.

You're traveling tomorrow to go on a trip.

You can even be in a game like all the players are getting together to play a game online.

Or it could be a sale or a new product is launched.

So, there's this time before the event, what can we do in that time?

There's the event itself when people are arriving at your event, what opportunities are there?

And finally, when people are at your event and they're spending time, how can we enrich the experience there?

Before we get fully started, I want to mention the technologies we're going to use.

We're going to start pretty basic and get a little more complex.

First of is Calendar Events.

Then we've got Push Notifications, then Core Location.

And a specific feature of Core Location, we call Region Monitoring.

This is also known as Geofencing.

You might know it like that.

And finally, we're going to talk about a new technology on iOS 7, iBeacons and that's the demo we'll show you.

OK. So, it's the time before the event, the event is coming up, what do you do?

You tell your users about it.

To remind ourselves in the timeline, we are now here, right before the event.

So this is an event, hopefully our users really care about this.

They're excited.

When you told them about it, they are looking forward to it.

What can you do in your apps to keep that excitement alive and what can you do to remind them of the event?

I'll show you.

Through a feature in the Apple Store app we called iPhone upgrade notification.

Let me just set the scene.

I will have to guess that pretty much all of you have an iPhone or have access to an iPhone.

Those of you that have bought it in the US, you know that US carriers like Sprint, AT&T, Verizon, they subsidized the cost of your phone if you sign a contract like two years.

When you want to upgrade your phone, depending on where you are in that period, maybe at the end of the two years, you get a full discount again of 199 and the carrier will subsidize that.

Maybe if you're midway through, you get a partial discount like 449.

And if you're early, maybe you don't get a discount.

So, as a user, you might want to get the iPhone at the best price so you got to keep track where you are in that contract and when you're eligible for that best price.

OK, so that's your event.

The event is the fact that you can get this new product, this iPhone at the best price.

OK, so you got to keep track of that date and the worse thing is it's dynamic.

Carriers can change it.

They can pull in the date, you know, maybe to incentivize you to buy early.

So what can we do in the Apple Store app to remind users of this event and make this process even better?

This is the iPhone page in our app.

You can learn about the iPhone.

You can choose the model and the color and you can buy.

When you buy, we're going to auto detect your carrier and we're going to tell you, "Hey, we need to go query the carrier on your behalf to find out what your price is."

We take some info from you that the carrier needs.

We're going to encrypt this and we're going to send it securely.

And then, we're going to come back with the price for your phone.

In this case, you're eligible for a partial discount of 449 for the 16 gigabyte.

On April 15th, you can get the full discount of 199 and that's all the features used to be.

And it would be up to you if you don't want to buy now to come back later and go through this process again.

Then we added Notify Me.

That's your way to say, "Hey, Apple Store app, I don't care about this to think about this stuff.

You tell me when I'm eligible."

OK, we can do that.

The first way we did this was through Calendar Events.

And we you tap there, we just put an event on your calendar.

You don't have to think about it anymore and they'll be there for you.

Or remember, it's a dynamic date and if the carrier changes the date, the Calendar Event is static.

So then we built it using Push Notifications.

And so, if you swipe that toggle to on, we're going to do is we're going to schedule a job on our service side and query the carrier on a regular basis and in intelligent way and we'll notify you the first moment that you're eligible.

So then, on April 15th, maybe the app is on the background, your phone is on your pocket, or whatever that date is, you're going to get something like this.

It's a push notification from our app, "Hey, good news, you can get the phone at the best price right now."

You swipe in, we'll take you to the app, we'll show you the best price, and you just tap to buy, and it can ship to your house or pick it up at the store.

And that's iPhone upgrade notification.

So we've taken this event, get this iPhone and we've reminded users about it and made the process easier.

So, we're going to talk about the example then we talk about the technology behind it.

First is Calendar Events.

This is simple to use but pretty effective.

And I'm not going to spend too much time here.

Pretty much all the skeleton code is here.

Innermost block is where you create the event and save it.

The outermost stuff is little more interesting.

It handles the privacy alert.

Your app has to ask user permission to use the calendar and that code is going to take care of that.

OK. Now, a little more sophisticated, Push Notifications.

This is the richer way to inform users and it's dynamic.

You can have those dynamic events 'cause your server is going to decide when to inform users.

It's pretty straightforward.

You register pushes you register for Push with this API.

You then take the Token with this API.

Now the token uniquely represents your app on this device.

Send that Token to the server-side where you store it.

When your server decides, "Hey, it's time to do a push, the event is here," you send the push to APNS via the Token and then APNS, that's the Apple Push Notifications Service, they're going to target that user by that Token.

They'll get an alert and then if they swipe in, your app will get woken up and you're going to have to handle this did receive remote notification method.

And that's it, pretty straightforward but pretty powerful way to inform users.

So we talk about the technology behind the example.

Now, we'll do some tips, tricks, and best practices to use this stuff.

First one is the big no, no and there's X over there in case you're wondering.

And it's the red X.

And it's the only red X that I have but it's very important because of this kind of stuff.

How many of you can identify what this, you know, "Hey, you haven't used me in two weeks or five days.

Please open me up."

Pretty annoying.

So, notify users of events they care about, only of events they care about.

'Cause if you don't, if you bought at them like this, they going to turn off, pushes globally for your app and you can't notify them again.

Or worse, you're going to hold down on your app icon.

And your app icons start jiggling.

You guys know why it starts jiggling, right?

'Cause they're scared, they're going to get deleted.

[ Laughter ]

[ Applause ]

And then they're going to click that X and they're going to delete it and never to download it again.

So don't let it happen to you.

How do you do it?

It's so simple.

Provide an opt-in method.

Tell them or explain the value of this feature and let them opt in like we did with our toggle.

You might be scared, "Oh then nobody is going to use it."

Believe me, if you explain the value, people don't want to think about these things.

They want to be reminded.

So, explain the value and they'll opt in then you know they want it.

Provide this with the correct moment in the flow.

In our flow, remember, you just checked your eligibility, you gave us all the information then we asked you to opt in.

It's a good time.

And provide some settings where users can turn this on or off and we'll talk more about that in the next slide.

So do not spam.

Thank you.

OK. So, In-App Notification settings, I'm not talking about the settings app here, I'm talking about settings inside your own app.

For example, in the Apple Store app, in our More tab, we've got this notification section.

You tap that, you're going to see something like this.

This is all the notifications we do.

The upgrade ones, we talk about on top, then order status, when does your order ship, when is it delivering.

Reservations, when is your Genius Bar reservation coming up?

And then location-based alerts which we'll talk about in the next section in Storefront Pickup.

So, this is great if you have many types of Push Notifications.

If you have only one, maybe you don't need this.

But if you have many types, this is a great way to handle it.

Why? Because it reduces the chance that a user will completely turn off Push.

If they're annoyed by one of this, they might turn that one off and keep the other ones on.

So, it's pretty obvious, pretty simple, a lot of people don't do it but this will be the best way to keep those pushes that people want on.

OK. Also, consider the time of day, very important.

So, don't send the push in the middle of the night, don't wake somebody up.

Don't disturb them.

Be polite basically.

This is also going to feel like spamming if you send it at the wrong time.

So, consider the time of day, consider when is best to send this, and also, think about time zones.

If you have a worldwide app, you want to think about time zones there or even in the US, you have multiple time zones.

One thing I recommend you to do is create a Do Not Disturb Time window on your server-side.

Maybe put it in your Push Engine.

Users have the do not disturb setting on their phone but they might not use that so you cannot rely on it.

So in this way, maybe in your Push Engine, if there's a bug or something and a request comes in your push engine at 3 a.m., "Hey, send this push."

Your Push Engine can be inactive and queue those requests using some queuing system.

Then when it's time to send pushes again, the Push Engine becomes active and it starts consuming from the queue.

It's kind of a last minute safety check on your server-side.

Just the recommendation we found pretty useful.

Final tip and trick I wanted to talk about is to be a good citizen and please clean up the dead push tokens.

Users might wipe the phone, they might delete your app, they might turn off pushes for your app so then these tokens are no longer valid.

OK? And you can send pushes to them, nothing is going to happen except you're going to clog the system for valid pushes and valid push tokens.

So please clean up.

Very easy, query the Apple Push Notification Feedback Service as there's where you'll query it using SSL.

You'll get a list of push tokens.

The list will be cleared when you get it.

And then you parse the list and just stop using them.

Usually that means you delete them on your data store or whatever.

So please, be a good citizen.

And that's it, that's the time before the event.

And now, the events arrived, it's here, it's today and users are arriving.

What do you do?

Welcome them.

And in our timeline, we are now at the event.

We're going to welcome our users.

When I say welcome them, I don't mean just roll out the welcome mat.

I mean roll out the red carpet.

Make them feel like a star.

How do you do that?

I'll show you with the feature we call Storefront Pickup.

No setting the scene now, I'm just going straight into this one.

Back to the Upper West Side Apple Store and meet John.

John made an order with the Apple Store app.

He's going to pick it up in the Upper West Side store.

He wanted to pick it up in the store.

When he made this order, the Apple Store app created a virtual perimeter, virtual fence or region around the Upper West Side store.

And we told iOS Core Location, "Hey, when John crosses this region even if our app is in the background or the phone is in the pocket, wake us up, we want to do something."

So when John crosses it, Core Location detects that, wakes us up, we take a look if John has an order and then we pop an alert.

And John sees this says "Hey John, you're near the store, there's an order for you here.

Do you want to pick it up?"

John says, "Yes."

And then we tell him, "OK, one of our employees is getting your order ready.

Just come on over."

And we send a signal to the back of the house where they start putting it in a bag and getting it ready.

As John approaches right on the front, he's going to get another notification.

And it's going to say, "Hey, one of our employees, Hillary, has your product, has your order, and she wants to meet you up at some location like the entrance."

And right as John and so John swipes that and goes into the app.

We'll show him a picture of Hillary.

So, you know who she is and can recognize her.

And then as John enters right around the entrance, Hillary will materialize.

More importantly, John's [ Laughter ]

order will materialize, OK?

And it's there for John.

Now John didn't have to go in line.

He didn't have to ask for help.

He didn't have to be bothered.

He was just coming to the store, he got welcomed and he's there for his important event to pick up that phone he got at the best price.

And there it is, that Storefront Pickup.

So think about in your thank you.

[ Applause ]

So, think about in your own apps what you can do here.

Maybe you have a restaurant, you can say, "Hey, we've detected you've come to the restaurant, welcome.

Go to the bar, we're going to get your table ready."

And then we'll buzz you when your table is ready and your phone can buzz them again.

You can eliminate those plastic, you know those pager things they have at the restaurant, you can eliminate that with your app.

So, pretty cool stuff you can do with it.

You can welcome people to the airport and say, "Hey, you know " I don't know if you've ever flown from an airport like SFO like on Friday at 5 or 6, it's very bad."

So, you can tell him, "Hey, here are the security lines that are open and here is the wait time in each line," for example.

So, a lot of useful things you can do with this.

What is the technology behind this?

It's called Region Monitoring.

This is a feature of Core Location.

You basically create regions, latitude and longitude and you give it a radius, right?

And then you call this API, start monitoring for region and then your app can go in the background.

Core Location will monitor in a very low power mode.

When Core Location detects that you've crossed a boundary, you're at the region, you're then your app will wake up and you're going to handle these delegates that it will call.

Finally, if you find the reason, there's a reason to wake the user up, they have an order or whatever, you then post the local notification using these two methods.

You can schedule one for later, on the bottom one, you can present one right now.

That's it.

That's all you need to do for a pretty magical feature, right?

So, Region Monitoring.

Now, tips, tricks, and best practices, very important.

We want to keep the battery full so minimize battery drain.

When you're woken up by Core Location, you're running in the background.

And you know and it's not a secret that running in the background and especially calling the server-side, network call is going to use up power.

If you do this too much, users will notice.

They will notice your battery They will isolate your app and they will do that thing, that story I told you deleting it, right?

So, what to do?

Just you know, it's obvious but minimize the background code and wait and you employ some safety checks.

I'll give you an example or/and caching as well.

I'll give you an example.

You have a restaurant at the mall or at the shop or whatever and the user walk-in in the mall, it keeps crossing your fence and the app is waking up, he doesn't even know it's waking up.

If you've woken up, call the server, you got the server data and you woken up 5, 10 minutes later, even an hour later, maybe that data is still fresh and you don't need to call again so you save on that.

And then employ some time stamps and things like that.

Maybe if you were woken up 5 minutes ago or 5 minutes before that, you don't need to do anything again.

You've done the work you need to do for the day and you can just shut down right away.

And maybe have some upper limit of how long you can be awake within a given day and enforce that to make sure that the battery doesn't drain.

Finally, I know you love to do this, but finally, you need to do significant testing on features like this both in instruments and automated testing but also realize nothing will replace this so, load you apps up on the phone, put in your pocket, walk around the mall or whatever your use case is and actually test this.

Make sure it's not draining.

OK, related topic is privacy.

When you're monitoring location or regions, this arrow is going to appear, right?

The Core Location arrow appears on the top right of users' devices.

They notice this thing.

And when they notice that they think often two things.

"Hey, Mr. App, you know where I am."

Why? Why do you need to know?

Or you're draining my battery, right?

You're constantly monitoring locations so you're probably draining my battery.

So what do you do about this?

First one is simple, be upfront with your users, just like the opt-in method we did with Push Notifications.

Ask them to opt in to this.

Tell them why you're monitoring location, explain the value of this.

And believe me, if you explain the value well, they will opt in.

So they're not surprised when they see that arrow.

And then other than the other battery savings stuff we talked about, monitor location only as needed.

Minimize that arrow.

If you don't need to monitor locations, do not.

There are three things you can do.

First one is the solid arrow.

That means you're monitoring a significant location change when your app is in background.

It means if a user moved all the way over there significantly, you'll wake up.

And so you'll wake up quite often.

If you really need to do that, do that.

Maybe you're a Sports app and you're tracking how far they're running, you might need to do that.

But if you don't need to, if you're just monitoring static locations like we are then use a fence and that will use less power.

And then if you don't need to monitor it, don't.

So if you don't have an order with the Apple Store app, we're not going to fence anything and you won't see any arrow, and users notice this and they appreciate that you monitor location as needed.

Finally, a tip for you guys who have many locations, maybe have a chain of stores.

Remember, Core Location allows you only 20 regions to monitor.

So you might want to be smart about how you monitor them, if you need to monitor all at the same time.

So, when you start, check the current location of the user, monitor those around the user.

Maybe provide some kind of zip code or address thing they can input, and then if they're traveling, you can fence another area.

Then you're going to need to update this.

For example, if they moved house or if they're traveling somewhere you update and you update when the app is awake.

When the app is awake battery is being used anyway, that's screen is being used, right?

So you can do it then and not use much more battery.

And if you really need to, when the app is in the background you can update your regions on a significant location change.

But remember, that's the solid arrow and you only do this if you need to do this.

OK, so we've talked about, you know, telling users about events.

We've talked about welcoming users to events.

Now the users at your event, at your location enjoying and spending time at your event, what can you do to enrich the experience?

We're coming towards the end now of our timeline and the user is spending time at the location.

So, let's give them something they will never forget.

Let's make them so, OK, don't scare them but I'm saying give them a memorable experience and let them get immersed in your environment.

How you're going to do that?

I'll show you with another feature from the Apple Store app.

We call this In-Store Mode.

So, this is the Apple Store app on a normal day, featured tab, you got your featured product, some marketing maybe Father's Day, alright?

But when you approach a retail store, the Upper West Side, when you approach the retail store with the app on or you turn that bring the app to foreground inside the retail store, we're going to detect that you're there through Core Location and will bring up this other UI.

We call this In-Store Mode and it takes over.

And it tells you what's happening now and it's all about that location you're at.

On the top, it tells you where you are in case you didn't know, Upper West Side.

And then from the bottom, just got some useful things, first is the current marketing or events that are going on, you can swipe through those.

You can get in to the virtual queue, get help, you can see who was in how many people are in the queue.

You can also get support in book a Genius Bar Appointment right there and probably you can use EasyPay, a service that's only available in the store where you take a product from the shelf, with your Apple Store app, you scan the barcode with your camera, put in your Apple ID password and you bought the product.

And you walk out with a product in your hand and the receipt on your phone.

So, these are some very useful services and information that we offer right at the store and our In-Store Mode to enhance the user's experience there.

The technology behind this, this In-Location Mode is again Core Location and we're using it now when the app is in the foreground and we just trying to get the current location.

It's an asynchronous process so your call start updating location and you get a callback "did update locations" and then you handle that.

So now, you know where the user is and you know where your location of interest is.

Compare the distance.

And if it's within a threshold, some kind of radius where you consider someone in the location, you pop open that the special UI, that's where that location.

It's that simple.

One thing I do want to also point out, when you use Core Location you can adjust the desired accuracy.

This is being a good citizen again.

So, if you're miles and miles and miles away maybe tell Core Location, "Hey, you don't need to monitor with such high accuracy.

You can monitor less accurately and when it comes close maybe to the mall where your restaurant is, start monitoring with more accuracy.

So, it saves a little battery with that.

So, In-Location Mode, now to talk about some tips, tricks, and best practices for this.

The UI is going to depend largely on your use case, depends on your locations, right?

So this is the one that's relevant to us but there are some generic guidelines you should follow.

First, be distinctive, be obvious.

This UI should catch their eye and it should be different in your day-to-day app.

Like this, you can't miss this, right?

And then, focus the user.

Bring front and center, those features and that information that matters at that location.

So, we just really fo we take everything else away and focus, you know, what's happening now and all the services that are offered at the store.

Finally, make sure this UI can be dismissed and users can access the normal functions of your app.

For us, there's the top right corner, there's the small white arrow thing, you can see it?

If you tap that, the UI will minimize and then you can access the other functions of the store of the app.

And just to compare the UIs, you can see just how different they are when you're in that location.

Next up, remember, your In-Location UI is probably only relevant in your location.

Imagine if we expose, get help, you know, or the EasyPay stuff at your house.

It's confusing and it can result in bugs too.

So make sure your UI is only there when you're at the location.

So you get a monitor for exit events and watch and it'll have listen keep listening to Core Location.

When the user has left the location, dismiss the UI.

If the user is looking at your In-Location UI and puts the app to background, when they start the app up again, do a quick check, are they still there or not and then you can dismiss the UI if they're gone.

There's one thing to be very careful about here, boundary conditions.

So, if that table is my center of my location and this is the boundary, right, where I'm in store.

Maybe I'm right here in Core Location says, you're in the location, I pop-up in the UI and maybe I slightly move and now I'm out the location.

I close the UI, I slightly move, I open the UI, it's annoying, right?

So, you don't want to do that flashing UI to the user.

So be careful.

The big tip I give you here is when you detect user is in that location, maybe you have a 50-meter radius or something.

Relax those conditions.

Increase them, make it 100 meters.

Or maybe it's also employed with some minimum time that has to pass or minimum distance they have to move for you to dismiss this In-Location Mode.

What you've done is you made the In-Location feature pretty sticky and so when so that you are sure that they have left the location when they do, otherwise, you'll get that flashing UI.

Anyway, if you can relax it just a little bit, it's not going to be a problem.

You're still not going to pop this UI at the house or something like that.

So important tips to remember here.

OK, we talked about Core Location and Region Monitoring to welcome the user to an event and to enrich their experience.

What's next?

OK, you know, what's next but How can we take this to the next level, right?

I'll show you.

With the new technology from available in iOS 7, it's a Core Location technology and we call this iBeacons.

I'm going to show you some examples where we use iBeacons.

I'm going to show you a little bit about the technology.

And then we're going to show you how to do this thing for real in code in a demo.

Two things I want to talk about.

First is Region Monitoring, the essence is the same except there's one key difference with iBeacons region monitoring, accuracy.

See, instead of using the traditional Cell Tower Triangulation, GPS, and Wi-Fi, when Core Location used to use that to figure out if you cross the region.

Now, Core Location tries to look beacon signals.

Beacons are just hardware you put out in your location and they emit in our case Bluetooth LE, Bluetooth Low Energy.

And we quote and those Bluetooth Low Energy signals can have specific IDs.

Your app can tell Core Location, "Hey I'm interested in ID XYZ or 123 this Bluetooth LE ID."

When Core Location senses that ID, it wakes your app up and you can do something.

So, let's see how these works in one of our examples.

I want to put aside the Apple Store app and I wanted to use a museum.

We're now in Paris, France.

This is the Louvre Museum in Paris, France and we put beacons on the entrance.

So, when a user approaches one of these beacons with the phone and our app is there, Core Location detects that, tells our app and we can throw up an alert and say, "Hey, welcome to the museum.

Your guide is ready to meet you."

User swipes in and we show pertinent information and tell them where the guide is.

Now, it's similar to the other thing we talked about, right, the other region monitoring but the accuracy is the difference.

You can do this right at the door.

Maybe if you have many entrances to the museum or whatever big location you have, each one can have its own iBeacon and it's a much tighter accuracy.

And you can know which entrance the user is for the guide to meet them.

Pretty powerful.

Now, you get see them more interesting.

Let's talk about ranging.

In ranging, iBeacons ranging enables the use cases around micro-location.

We've cracked the nut on macro-location, right?

We know you're in this room maybe or in this building.

We know you're in a restaurant.

We know you're in a movie theater.

We know you're in store.

We know you're in a museum.

But how cool would it be if we know you're at that table versus at the bar?

We know you're at that departure gate versus this departure gate.

We know you're, you know, in front of this shelf instead of that shelf.

We know you're in front of this painting instead of that statue.

And you can open up a bunch of use cases there and only and show some great features that are pertinent to the user's immediate surroundings.

This is very powerful and I'm going to show you a very simple example now.

But what's behind this is that Core Location not only sees a signal but it can tell you how far away from a signal you are and that's the power.

This is estimated based on signal strength and you can get a range basically immediate range, 10 centimeters away or so or near range about two to three meters away or far range, and then you react your app react based on that.

So, at the museum, we've heard of this painting right, and we want to go and look at it.

And we're there with our Museum app exploring the museum and we're constantly querying Core Location ranging to see if we're near an artwork and we've put some beacons at the artwork.

We put a Mona Lisa beacon right on near the painting, it's hidden, you can't see it but it is emitting Bluetooth LE.

And as you approach with your app, Core Location tells us and we'll pop a special UI to do with the Mona Lisa and we'll tell information about the Mona Lisa and the artist.

And whatever makes sense for your use case, we can expose some features like, "Hey, do you want to buy," I don't know, "A print or a Mona Lisa calendar?

Ship it to your house?"

Anything like that.

So, pretty powerful stuff right at the Mona Lisa.

And then if you walk away, we'll dismiss that UI.

And you maybe you walk to the Winged Victory statue also at the Louvre Museum, and when you're near by there, you detect that beacon and you show them a different UI to do with the Winged Victory and you show that information there.

Have you ever been to the museum, right?

Have you ever had those audio tours, have you ever had those Walkman things?

You know what, so you don't need that anymore, no more Walkman.

You can just use your app as a museum guide with this kind of stuff.

A little bit about the technology.

[ Applause ]

Thank you.

Thank you, I appreciate that.

A little bit about the technology.

As I said at the basis of this is Core Location, monitoring Bluetooth LE signals and it can just do Region Monitoring as well as it can do ranging and detect distance.

And Region Monitoring is when your app is in the background usually.

But for ranging, your app needs to be in the foreground or you can do it scan on wake which means when you wake your phone up even if your app is not on, Core Location can do a scan for you there.

It's pretty powerful and you can bring up a notification.

What's a beacon, you might ask?

It can be a lot of things.

Various hardware can act as a beacon.

You can buy this third party program, program them to emit whatever Bluetooth signal but also, your iOS devices can be beacons.

So your iPads, your iPhones with the new iOS 7 SDK, Public SDK, you can program them to emit whatever signal you want and you can do that dynamically and programatically and vary depending on what's happening.

So, imagine at the museum, the painting or the statue has a sign like an iPad is the sign, like a smart sign, like we have in our retail stores maybe, and you could tell the information about the painting but if it's crowded, it's still emitting Bluetooth LE in on your app, we can detect that and show them whatever UI.

So, pretty powerful that you can use iOS devices for this too.

You can try it out right now.

Finally, to remind you the big advantage here is the accuracy and that range that distance awareness that lets you do things you could never do before.

And also worth mentioning, one Beacon ID, you can have, maybe have a chain and you do want to fen you know, you want to fence more than 20 locations.

Once Beacon ID can represent can be one the beacons can be deployed in all these locations with the same ID.

So, one beacon ID represents all your location and you're no longer bound by that limit of 20.

So, that's pretty powerful too.

Thank you.

[ Applause ]

All right, so, I'm not going to keep talking about this stuff.

I've talked enough.

Rather than talk, what we like to do is show you a demo on this now.

And I want to invite Yingfeng Su.

He is the Engineering Manager on my team.

He leads the team that actually built all the features you saw today.

And one of his [ Applause ]

Thank you.

[ Applause ]

And Mathieu Roig is an engineer on his team.

They've actually built this Museum app, this demo app that I showed you and they're going to show you how this works in code and do a demo for you.

Take it away.

Thank you, Filip.

Hello everyone, my name is Yingfeng.

I'm here to show you two exciting demos.

Both are related to the iBeacons technology newly introduced in iOS 7.

I'll do code walkthrough in Xcode.

Then I'll also show you how they actually work on a real device.

So, the first demo I'm going to show you how to welcome your customer when they arrive at the entrance of your location.

So, you probably think this feature sounds complicated.

It must take a lot to time and effort to build.

That's not necessarily the case.

So, please look take a look at the screen where I'm showing you my Geofence Manager class.

This is where I grouped all the Region Monitoring related code in a one place.

There're only two methods you need to implement in order to make this entire thing work, so let's take a look.

The first one is called Register Beacon Region.

This is where you tell iOS, "Please monitor region for me even if my app is not running."

So, let's take a look at the commented code first.

So this, the commented code shows how you are going to do it today with iOS 6 Region Monitoring.

You need to use a latitude and a longitude and a radius, then you monitor that region.

What I want to show you is that by just replacing two lines of code, you can easily convert a regular region into a Beacon region which gives you more accuracy.

And other than that, everything else works the same.

You don't have to touch any of your other code.

So, let's take a look.

The first line, you need to create a UUID.

This is your way to tell iOS just monitor signals from my beacons.

Don't monitor someone else's beacon.

You can use tools like the UUIDGen to generate a random unique identifier.

Next line, you create a CL Beacon Region object using that UUID you just created.

And next, of course you need to create the location manager itself and assign a delegate in order to receive the callback.

And the last, this is a real deal, where you call the location manager start monitoring API to tell iOS to monitor this region for you.

iOS is smart enough to look at the type of the region object you pass in and determine what technology should be used to monitor that for you.

If you pass in a beacon type, it will use Beacon technology but the API is exactly the same as you have today.

So, that's the method.

I would call this method only at the most relevant time.

So, when user made a dinner reservation at your restaurant, they just reserved the guided tour at your museum or they placed an order and will pick up at your store.

Those are the perfect time to start such monitoring process.

You don't want to do it too early.

You don't want to do it blindly at every startup and have that arrow show up unnecessarily.

So now, your customer finally comes to your location.

At the entrance, iOS detects that the user crossed the boundary of this region.

So, this location manager did enter region callback will be invoked.

Before I expand this method, let's take a minute to think what we are trying to do here.

So, the ultimate decision we want to make is whether it's appropriate to post the welcome notification to the user.

If the user's order is not ready, it's not the time for their dinner, there's probably no point to show anything to them.

However, in most of the systems this decision can only be made on the server-side because the user's order status, their reservation information, their guided tour schedule, those are all stored in the server database.

Your app doesn't have that information right away.

That does mean your app will need to make a server call potentially in background because this will wake up your app in background when your app is not running.

That will involve another technology called the Background Execution.

It's part of the iOS multitasking and there are lots of documentations and sessions about that so I won't get into the details.

I'll just show you how we use it in our particular example.

Now, let's expand the code.

The first line is just a sanity check to make sure my Geofence manager is the right object to respond to this event.

Because the region events are delivered to all of the Core Location delegates of your app, not only the one that registers for this region.

So, you need to keep that in mind.

The second line is just my way of telling you, "Hey, I'm only demonstrating the background case."

Once you understand this, you can easily figure out the foreground case on your own.

It's even simpler.

The next one is the safety check I'm talking about.

So, imagine your location is in the middle in the middle of a busy area.

Your restaurant is in the middle of a mall.

It's totally possible for the user to cross the region multiple times in a short period.

If you blindly start your app and do all these resource-intensive things like making server calls every single time the user crosses the region, for sure the user will notice that their battery drains faster than usual.

You don't want that to happen.

You want to prevent that.

So you can what you can do is to use information such as the timestamp of the past location events to see if enough time has elapsed since the last time they crossed the region.

If that's not the case, you should tell your app to just go back to sleep without consuming any more resource.

That's key to saving battery.

Now, we finally enter the real business.

First thing you need to do is call UIApplication begin background task API to request additional background time because you are going to do a server call and it might take a few seconds.

So, there's a lot of the documentation for that.

There's only one thing I want to call out is that be a good citizen when your app is in the background.

Implement a meaningful expiration handler block so that iOS can invoke to do the cleanup work in case your task runs for too long.

If you don't do that iOS will eventually terminate your app.

Now, you requested the additional background time, you can actually start the server call.

This would be exactly the same if you wanted to do it in a foreground.

Here I'm using my Service Manager Object to take care of all the URL connection, HTTP details for me.

So, what I'm doing here is providing a completion block that will be invoked by my Service Manager when the server data has been received by the app.

So, let's take a look on what we do.

Rule number one, for any client-server app, check against the error, never ignore an error, OK.

And if you get no error and you actually get meaningful information from the server such as the user's order is ready for pick up or dinner the table is ready for their dinner, you create the UILocalNotification object.

You fill in the details using the information you received from your server, and it's very easy, you just call this Present method to UIApplication object to present that.

Also you can optionally put a private user info where to your Local Notification.

So later, when you user opens it, you know what notification it is and how your app should react.

That's pretty much we're pretty much done.

There's one last thing you need to do.

Remember you began a Background Task earlier.

You need to end it.

If you don't do this, your app will be terminated by iOS eventually.

So that's all the code you need to add in order to make this work.

Now, let me show you how this actually works on the real device.

So, I'm the visitor.

I have a guided tour booked at the Louvre Museum for today.

As I approach my phone has been in my pocket.

It's still in the locked mode and I'm expecting a welcome message to tell me where I should meet my tour guide.

So, in order to do this demo because I cannot move around with this cable attached, so I'm going to get help from our engineer Mathieu.

Mathieu is holding an iPhone that is programmed to be a beacon transmitter.

He's got this little app where he can turn on and off different beacon signals.

So, when he turns on the Region Beacon it will be exactly the same effect as if user crossed boundary of the region.

So, let's see how it works.

Mathieu, can you tun on the region for me?

As we can see, as soon as Mathieu turns it on, the notification is posted on the user's Welcome screen that says.

[ Applause ]

Thank you.

It gives you some meaningful information.

If as a user, I swipe and open, the app is launched in foreground and you have the freedom to do whatever you want.

So, again, this is at the entrance of your location, OK.

So comparing to the regular Geofence where you have today, it probably notified the user at parking lot.

Now with this, you can notify them at the entrance.

So, that's my first demo.

Only two methods, it really couldn't be any simpler.

Let's move on to the next demo.

The next demo is about ranging use case.

So, imagine, you are the owner of a large museum.

You have hundreds or thousands of artwork pods in your exhibition area.

What you can do is to attach a beacon to each of the artworks such that when user is in your museum and they're running your Museum app, they can get additional information about the artwork they are closest to.

So, let me show you how to do it in code.

Again, two methods.

First method is to start to the ranging process.

This tells iOS, "I'm ready to receive signals.

Please, monitor beacon signals around me and report them back to me."

So, 3 lines of code.

First thing first, you create a UUID.

You need to use the same UUID between your app and all of the artwork beacons in your museum.

Maybe you have 500 of them.

It doesn't matter.

You use all the UUID you used the same UUID on all of them.

So, there's really no practical limit for you.

And then you create a CL Beacon Region object.

It's very similar with the previous demo.

And the last is this time we're calling the Start Ranging API instead of a Start Monitoring API because we want to do active scanning.

So, that is it.

From now on, iOS will start monitoring the signals around you and then report them back to you.

I would call this method whenever my app goes to the foreground and the user is confirmed to be within the range of my exhibition area.

So let's take a look at the Core Location delegate callback.

Location manager did range Beacons in region.

This is where iOS tells you, "I found one or more beacons around you."

Notice that the beacons parameter is an array because at anytime, you can see multiple beacons around you.

They are sorted by the perceived distance.

So, the one that's believed to be the closest is at the top of the array.

So, let's expand the method and see what we do here.

First line, I'm just trying to use utility method to inspect if the closest beacon is within a desired threshold.

Here, I'm using CL proximity near as my threshold which represents a distance of roughly three meters.

So, this entire line basically means try to find the closest beacon that is within three meters.

If one the reason I make it into utility method is because I may want to use it somewhere else in my app and it makes unit test easier.

But, inside it this is really just objectAtIndex zero, casted back to the region and check the proximity property.

And if one is found, I can inspect the major value property on the Beacon to tell whether it's the painting or it's a sculpture.

So, we programmed all the artwork beacons using the same UUID.

So you might ask, "How do I tell whether it's a painting or sculpture?"

There are other customizable values on the Beacon.

They are called major and the minor properties.

Each of them is a 16-bit integer.

So you can define the value of them.

So, in my case I specify one to be the Mona Lisa paining and I used two for the Winged Victory statue.

So, by reading the major value, I can give a hint to my UI code, "OK, this is Mona Lisa.

That is the Winged Victory."

So you can show different pages.

And of course if user has walked away from the exhibition area, this method will return nil and we'll just dismiss the information page we just showed earlier.

So let me show you how this actually works on a device.

So, I'm running my Museum Guide app.

OK, it's the same app and it's in foreground.

So, the ranging process is already working.

So again, I'm going to get help from Mathieu to turn on and off different artwork beacons which is exactly the same as if user approaches or leaves certain artwork.

So, Mathieu, can you please turn on the Mona Lisa beacon for me?

As we can see as soon as Mathieu turns on the Mona Lisa beacon I'm not touching the phone by the way.

[ Laughs ]

So, we are showing an information page about the author and what year it was made.

You can do whatever you like that's relevant to this particular artwork.

Mathieu, can you please switch to the Winged Victory statue?

So now, I walk away from Mona Lisa and I walk towards the Winged Victory statue.

You can see the app is smart enough to swap the information page.

Now, can you turn off everything?

So, when Mathieu turns off everything, we are dismissing that information page.

And the app is still ranging as long as you are in the museum.

So, that is the end of my both demos.

We are very excited about these new technologies.

Everyday, we keep thinking how we can use these technologies to further enrich the customer experience in our app.

I hope you like them as well and think about how you can use them to deliver more personalized services to your customers.

Thank you and I'm going to give this back to Filip.

[ Applause ]

OK. Hope you guys enjoyed that demo.

It was live and you're one of the first people to actually see iBeacons in action for real.

So, like Yingfeng said, we're really excited about this on our side.

So, I hope you guys are too and just go out there and build some magic with this feature.

I'm going to summarize things up now and as we talked about this, some key iOS technologies, calendar, push calendar events pushes Region Monitoring, Core Location, and iBeacons.

And they're simple to use but so effective and you guys can make some truly great experience with these.

So, go out there and use them but use them wisely, use them properly.

That's how we have tips and tricks here for you.

Finally, if you have been done it already, download the Apple Store app, you can see all this in practice and you can pull along and see what we do in future.

For more information, our evangelist is Paul Marcos.

This is the Apple Store app, the Reference app.

You can find it here or download on the App Store and as always the Apple Developer Forums are there for you.

There are some related sessions I want to point you guys too, Yingfeng talked about running in the background.

You're going to find a lot all about that and what's new with multitasking.

I really recommend that one then Integrating Passbook in Your Ecosystem, that's another session by my team.

Well, again we approach it from your perspective.

We've implemented the Apple Store gift card pass.

Pretty complex pass and we talked about how we did that in the tips and tricks there so you guys can implement your own passes.

And then, of course what's new in Core Location.

Here, you can find out a lot more about the iBeacons and all the other Core Location technology we've talked about.

With that, I want to thank you guys for coming to this talk.

Thank you [ Applause ]

for coming to WWDC.

Hope you had fun.

Apple, Inc. AAPL
1 Infinite Loop Cupertino CA 95014 US