Hey everybody was going on this is Caleb with Def slopes dot com and in this video we're going to go
ahead and request Siri permissions and go ahead and enable that that we can use.
Siri that's kind of an important piece of this course.
So let's go ahead and let's open our project here and let's get started.
So in order to do this we're going to just start with work out VC as it is and what we need to do to
actually use Siri kit is we need to import a framework from Apple called intense and not like intense
like intense like I intend to do something so go ahead and import.
Intense.
And this library actually is going to give us access to all the cool Siri cat stuff and all we need
to do to request access for Siri is to call upon a class called Ayane preferences and there's a function
inside that called request Siri authorization.
So go ahead and call I and crafts like so preferences and preferences dot and you'll see this has to
do with requesting Siri.
Now you can access the Siri authorization status Siri language code and you can request Siri authorization
so select that and then for the handler go ahead and just press enter and it's going to return and I
end Siri authorization status which is either authorized or not authorized.
So just name it status.
And what we're going to do is we're going to check if the status is authorized will print Siri get authorized.
Otherwise we'll just say unauthorized and it's not the most elegant way that we could do it.
But at this point all we really care about is if it's authorized or not.
So go ahead and type if status equals and Siri authorization status dot authorized.
OK we're going to go ahead and just print out Siri kit auth or arised.
And this is just for our knowledge we're just going to print it out to just show when the authorization
actually happens.
But if it's not authorized we're going to present or print rather Syrie kit on authorized.
OK.
So very cool at this point we have successfully requested Siri authorization.
So that's awesome.
But there's one thing we need to do now.
If you know anything about Iowa.
You know that when we request certain services from our device we have to give a usage description.
It's the same for requesting location requesting you know the user's microphone or the camera.
We have to tell them why we're trying to use it.
So to do so go into info up the list click the plus button right here on a supported interface orientations
and go ahead and type privacy dash Siri usage and you'll see there is a Siri usage description.
Now the reason we're using this.
We're going to say we want to use your voice to start a workout session.
Press enter and that's why we're using Siri to start a workout session.
So that is finished.
We have used iron preferences to request Siri authorization and that is called When the view loads.
OK.
Now that's pretty cool.
And that is how we're just going to use it for now so I don't know about you but I want to build and
run it.
I want to see if we can successfully authorize our Siri.
So click build and run.
It's going to pull open the simulator here in just one moment and we'll be able to see if what we did
was successful.
So it's going to do its thing it's going to think we're going to check and when it pops open we get
a crash.
Why is that interesting.
So let's see what the problem is.
Terminating app due to uncaught exception an internal inconsistency exception use of the class I preferences
from an app requires the entitlement camarade Apple doc developer what Siri did you enable the Syria
capability in your X code project.
We didn't.
So that's another important thing we need to think about that you may not have realized you can't just
do it in code.
We need to go into our project go to capabilities and turn on Siri check it out.
I'm going to go ahead and turn it on.
It's going to automatically do its thing and it's going to add the Siri feature into your app ID.
Now we have a leg day.
Entitlements file and Siri is a part of it.
So now we actually have that proper entitlement from the apple developer site.
So build and run one more time.
And now we should have that problem alleviated.
We shouldn't crash for that reason look at this would you like to use leg day with Siri some of your
leg day data will be sent to Apple to process your requests.
We want to use your voice to start a workout session.
Now when I click don't allow it should print out saying Siri kit.
Unauthorized.
And it did look at that.
Now I'm going to build and run it again so that we get that request again.
And let's see what we get to do.
OK so it's still saying unauthorized and I think that's because obviously it saves it because we set
that info up the list.
So let me delete the app and there we go.
Let me rerun it here.
Now that it's deleted we have a fresh copy and it's going to ask me if I want to use leg day with Siri.
So now if I click OK it says Siri could authorize then of course if I build and run it again it would
still be authorized because that is now set and this app is now ready to use Siri I'm not even kidding
it is that easy to use.
So amazing work guys.
In the next video we're going to go ahead and create what's called a Siri kit intense app extension.
And we're going to configure it for use with a workout specifically there are some things we got to
do to make sure it's ready for a workout.
So I hope you're excited it's really awesome stuff.
But we we now have access to Siri.
Thanks to I-and preferences.
So let's head over to the next video and let's create that Siri kit intense app extension.
I'll see you there.