Enabling Phone Calls6:01 with Heath Hodgert
In this video, we'll enable our app to make phone calls to our favorite pizza joint.
Our pizza calculator service now doesn't have the correct signature. 0:00 So we need to create a phone dialer to pass into it. 0:04 The context, like I said, is also our activity. 0:17 So we can just pass in this. 0:21 Let's run the Android app and see how it looks. 0:30 First, we must set as our StartUp Project the Android project. 0:34 It's already selected our preferred device to debug. 0:40 Now that our Android emulator is up and running, we can enter a value, calculate. 0:45 You see our new message with 11 pizzas, and we can call. 0:52 You notice the call button didn't do anything. 0:59 That's because we didn't add an event to it. 1:02 Back in the main activity, let's add an event to the call button. 1:09 We'll use our pizzaCalculatorService. 1:25 And call our pizza parlor. 1:30 Now if we run it again. 1:40 We enter the number of people. 1:44 We get our message. 1:48 And when we call, we get the call dialogue. 1:53 Now let's do the same thing for iOS. 2:03 In the phone dialer for iOS, we'll need to have a handle on the UI View Controller so 2:28 that we can interact with the interface. 2:33 So let's pass it into the constructor. 2:37 Now that we have a handle on the UI View Controller, 3:13 we can implement the Call method. 3:15 We will also need to create a URI here. 3:31 Using the iOS framework. 3:37 And with iOS, we first wanna test to see if we can actually open this URI. 3:52 So if we can open the URI, it will just open. 4:14 But because we put a not sign here, if it doesn't open, 4:17 we can handle it in a different way. 4:21 We'll use an alert controller. 4:30 To create a message. 4:39 I've given this alert controller a title and a message. 5:11 Now we need to indicate the style. 5:16 If we wanna close this dialogue, we'll have to handle the OK button, but 5:24 in this case we're just going to close the dialogue. 5:28
You need to sign up for Treehouse in order to download course files.Sign up