Of course, we need a local client project to interface with AWS for the user authentication, database, and any other features we add to the app. In our case, we'll create an iOS app project. Learn how the app needs to know about the project created from AWS Mobile Hub as well as use the SDK installed via CocoaPods.
- [Instructor] We looked at how to create our project and the app presence on AWS. Now, let's create the counterpart on our machine for developing our app. Again, we're gonna be using iOS app in this course, so we'll be using Xcode to develop it. We're also gonna need to install some CocoaPods, so we wanna make sure that that's prepped on this machine as well. Then we're gonna add the AWS Mobile SDK to the project and add the configuration file that we downloaded in the process of creating the app on AWS.
So the steps will be to create an Xcode app project, install the necessary CocoaPod, AWSMobileClient, and add that to our project. So let's get started in Xcode. So we start up Xcode and we select to create a new Xcode project. We're gonna use a single view app and make sure that iOS is selected for our templates. We'll click Next and give our app the same name that we gave it on the server. It doesn't have to have the same name, but in this case, we'll go ahead and name it Notes like we did on AWS.
We're gonna give it the organization identifier with the reverse DNS of com. example. notes. We'll click Next and select to save it on our desktop. So now that we've created our app, we wanna add the CocoaPod. So the first thing we need to do is make sure that CocoaPods is installed. For instructions on how to install CocoaPods, you can go to cocoapods.org. We'll install it with this command with the sudo gem install cocoapods.
So I'll copy that and go to the terminal. I'll paste in the command and run it. Once CocoaPods is installed for the machine, I'm able to install CocoaPods for individual projects. We created our project on the desktop, so I'll navigate there to install the specific CocoaPod we need. If I do a listing of my directory, I see that I've got my Notes project and other related files.
Now that I've installed CocoaPods, I can initialize a CocoaPod pod file that specifies what CocoaPods are related to my project. So I'll type pod init. Now, when I do the same ls, I have a pod file in there. I'm gonna edit that pod file and add the CocoaPod that we need to install for our project. You can use whatever editor you like. I'm using VI. So I go down to the line under the comment for Pods For Notes, that's our project, and I'll insert pod, single quote, AWSMobileClient.
Now, I'll save the file. And run pod install. This will install the CocoaPod for our project. It will also create an Xcode workspace that we'll use going forward instead of the Xcode project file to open our project. With the installation complete for our CocoaPod, again, we can do an ls. And notice that a few more files have been added, specifically the Podfile.lock and the Pods directory that has the source code and everything necessary for the CocoaPods under it.
Also notice our Notes.xcworkspace. We'll use that instead of the project file going forward. If we look at the Podfile.lock, we can see the different versions of the pods that were downloaded and used. We didn't specify a version, so it's using the latest and that's fine for our project here. If you need to specify a specific version of the pod file to use, you can research that at cocoapods.org as well. So now, we're gonna close Xcode and open it back up with our workspace. So I'll type open Notes and use the workspace.
So here we have our workspace with our Notes project in it and also, the CocoaPods that were downloaded. Notice that the mobile client requires the core and the authcore as well. Other than that, it's mostly a pretty regular Xcode project for an iOS app. We have our app delegate, our view controller, and so on. If we look at the app delegate, we need to make one change to the start up. In our application didFinishLaunchingWithOptions, we're also gonna fire up the AWSMobileClient.
So we're gonna import at line 10 and type import AWSMobileClient. Once we've set our import to AWSMobileClient, you notice that it says there's no such module. So let's go ahead and build, so it'll include this module and we'll get the auto-complete for the rest of the code we need to write. Once we have a successful build, after line 19, we'll add a line to start up our AWSMobileClient.
And we'll say let awsStarted equal AWSMobileClient .sharedInstance.interceptApplication and we'll use the one with didFinishLaunchingWithOptions. We'll pass in as the first parameter the application that was passed into this function. In the didFinishLaunchingWithOptions will be the same launch options that were passed in as well. Now, in line 21, instead of just returning true, we'll return awsStarted.
That way, if we need to do any other checks additionally to this one, we can also add that to the return. If your app is gonna be launched by other URLs or push notifications, especially in the background that you need AWS access to, in those functions, you'll also need to use the AWSMobileClient and share an instance and intercept those launches as well, similarly to how we're doing it here in didFinishLaunchingWithOptions. Again, now, we should be able to build.
And if we run our app, it'll start in the client that we selected. In this case, the iPhone 8+. Of course, our app doesn't do anything as far as UI or functionality. But just to make sure that it'll launch successfully in the simulator, we'll go ahead and start it. When we start up our AWSMobileClient here, it's gonna expect the configuration file to exist in here. So we need to add that. That's the configuration file we downloaded when we created the project app on the AWS Mobile Hub dashboard.
So I'm gonna go over to this Notes folder and select Add Files to Notes. I'm gonna go to our Download folder and select Awsconfiguration.json file. And I'll add that to our project. If we look at this file, we see that there's some basic configuration settings that were created when we created our project in the Mobile Hub. We have our pool id, our region, the identity manager. These are some things that will be fleshed out as we add our features.
Notice that there is one feature that's already created with an app id for analytics. That's automatically created and included into your project when you create it, whether you use it or not. In this course, we won't be using analytics. So we created our Xcode project and we installed our AWSMobileClient CocoaPod. We added the SDK using the CocoaPod to our code and then added the configuration file. Once we added the CocoaPod, it created the Xcworkspace.
We'll use that going forward instead of the project file itself. In the app delegate, we imported the AWSMobileClient code that we downloaded in the pod, so that we could also return in the didFinishLaunching the results from firing up the AWSMobileClient. Now, we should be able to run our app in the simulator. And it launched successfully. The UI is empty, but that's all we expect for now. Next, we'll look at how we add the additional features to our project.
- AWS Mobile introduction
- Create your app project
- Adding authentication
- Adding Facebook and Google logins
- Configure data and file storage
- Reading, updating, deleting, and querying data
- Uploading, downloading, and deleting files