All right.
So for those of you guys who have a physical iPhone device or an iPad device even, and you would like
to run the Flutter apps that you create onto your physical iOS device, then you are in the right place.
That's exactly what we're going to cover in this lesson.
Now, before we can get started there's a couple of prerequisites that you have to fulfill before you
can actually do this.
One is you must have an Apple I.D. So you must have registered with Apple at some point, giving them your
email and have a password.
Now this Apple I.D. doesn't have to be a developer account.
So it could be any sort of Apple account that you have. Anyone that you use to say download apps from
the App Store, or the ones that you use to log in on your iPhone.
Now the next thing you need is a iPhone or an iPad device.
Our apps are not going to run onto a watch or any other type of Apple device. It has to be something
that can run iOS.
So one of these two. And then three, you're going to need Xcode already installed, which we already did
previously in the setup instructions. If you haven't done that, then you'll need to do that now before
we can continue.
And finally, you're going to need a good quality USB cable.
And strangely enough, we've discovered through years of teaching students that USB cables are not created
equal.
And some of them will only transfer data whereas other ones will only transfer power,
and you need both power and data.
So best case scenario, you have the original cable that you got from Apple, which is hopefully not yet
frayed because they tend to do that. Or you have a good quality USB cable from another provider.
Once you've got all of these four things, then we're ready to move on.
And just a word of warning,
there's quite a few steps that we have to go through, and they're kind of like the hoops that you have
to jump through before Apple will actually allow us to install our app onto our phone.
And as you can imagine, Apple is very serious about security.
So there's about 10 steps that we have to go through. But I will go through each of them with you, together
step by step.
So the first step is you have to make sure that the iOS version on your physical device is compatible
with the Xcode version.
Now generally speaking, the Xcode version is two versions behind iOS.
What does that mean?
So here I have my Xcode application open, and you can see that the version that's registered on it
is currently 10.2.1.
Now on the right hand side here, I've got quick time that's rendering my current iPhone.
And if I go into settings, and I go into general and about, then you can see that the current software
version I'm running is 12.2. The number that we're interested in is that, if you have an iOS version
of say 12, then minus 2 becomes 10.
So Xcode has to be at least version 10 in the first number.
Now the second number has to be lower on the iPhone.
So if this is a 2, this has to be a minimum of 2.
So if I had Xcode 10.3, 10.4 etc. that will also work with this version of
iOS.
But basically, your Xcode has to be ahead of, or equal to your iOS software version.
And there's a gap of 2 on that major number.
So 10 matches with 12. 11 would match with 13.
Eventually when Apple releases iOS 13.
But if your Xcode is too old, or it doesn't match with the iOS version, then the easiest way is to
update Xcode to the latest version.
So open up the app store and update it there.
It is very hard to go back in time for your iOS version.
It's much much easier to upgrade Xcode to the latest version.
Now however, some of the latest versions of Xcode will require you having the latest version of Mac OS.
So if you go into this little Apple sign and you click on About this Mac, you have to make sure that
you're running Mac OS Mojave to be able to run the latest version of Xcode.
So if you have one of these things that are a bit older, then you might end up initiating a chain of
updates where you first update your Mac OS and then you update your Xcode. So you go onto the app store
and you can see that there is a later version of Xcode but it's not letting you update,
then the reason might be because you have a older version of Mac OS. Because there are minimum requirements
on all of these pieces of software.
So you can see here, we need at least Mac OS 14.3 or later. Which is exactly what I have,
I actually have a later version of Mac OS.
But once you're done with that and you've made sure that your Xcode is compact with your iOS version,
then we can move on to the next step, which is to install homebrew.
Now we're going to do this by following the tutorial on the Flutter docs page.
So under install, when we go to the Mac option and we go to deploy to iOS devices, you can see that
there are detailed step by step instructions.
Now there's a couple of bits missing here that I think are really important which is why I'm walking
you through it in video format, but there's a couple of other things that we definitely have to do.
And the first thing is to install homebrew.
So if you click on this link right here, it'll take you to brew.sh and on this page it will show
you how to install homebrew.
So all we have to do is to copy this line in its entirety, so we hit COMMAND + C to copy.
And then we're going to launch terminal.
So if you go into this upper right corner and click on the magnifying glass, you'll launch Spotlight
and then we're going to search for something called a terminal, and we can hit ENTER
once it finds it to launch our terminal application. Now once terminal has launched, then you're going
to paste that command you copied over, and you get to hit ENTER to install homebrew. And you can leave
it running for as long as it takes. And then go ahead and hit ENTER to continue.
And it's going to ask you for your password.
Now the password it wants, is the one that you use to log into your Mac. And your user account on
your Mac that you're currently logged into, has to be one with Admin privileges. Because it's going to
be installing homebrew onto the computer for all users to use.
So I'm going to type in my password and notice that it doesn't actually show what I'm typing, so you're
typing blind.
And, if you get it wrong, it'll just tell you so you can try again.
But once you're done, hit ENTER, and it will continue installing homebrew.
Now you'll know it's done because they'll tell you installation successful, and you will also be able
to see your prompt which is your user name and also the $.
So now that we're done with installing homebrew, we're going to be using homebrew to do a couple of things
that Flutter will require to be able to run your app onto iOS. Here under Step 3, in deploy to iOS devices,
you're going to copy each of these instructions one by one and you're going to paste it into the terminal.
Right here, and then we're going to hit ENTER. Now, as it says here,
the first two steps here is because, Flutter is currently using a opensource package which is developed
by an external developer, and these two steps may go away at some point in the future.
So maybe when you're looking at this page sometime down in the future, you might not see these two instructions,
in which case, you don't need to do it anymore.
So this is just a quick heads up.
But as of right now it is still an essential step if you want everything to work.
So once you've done that step, then you're going to go and do the next step and you're basically going
to go through this one by one, until you get to the very bottom. And they will take different amounts
of time to complete, but you will always know once it's done by seeing your prompt and then you know
that it's time to add the next line of code from the Flutter website.
And when you get to this line where it says 'brew install', all of these things, 'idevice installer ios-
deploy cocoapods.
This is the one that's going to take the longest basically.
So, this is one where you have to be really patient.
So once that's all done, we're going to copy the very last line which is to set up something called cocoa
pods, and this will take a little while as well.
Now once that's complete, you should see 'Setup completed' and we're now done with Step 3, and all of this.
So we're now ready to move on, where we open up Xcode, and we add our Apple I.D. So in order to do this,
you're going to go into Android Studio, and you should have the 'I Am Rich' project already open.
If not, go ahead and open it from file, open or open recent.
You might see it in there as well.
And once you're here, you're going to locate the iOS folder in your project navigator.
So if you're in a different view, say the Android view etc. then make sure you're inside the project
view. And you're going to right click on the iOS folder, and go to Flutter, then open iOS module in
Xcode.
And this should automatically open up Xcode, and open up the runner project which contains all of
the iOS part of our 'I Am Rich' app. Now,
if that doesn't work for you, then you can also go ahead and right click on this iOS folder, and click
on 'Reveal in finder' and once you're here, you should be able to expand that folder,
and here, you can simply double click on the runner.xcworkspace to be able to launch it inside
Xcode.
Now, once you hear, you're going to click on the runner project. So it's the one that has the blue icon.
And now you're going to be adding an account.
So here where it says team, if you have never developed an iOS app before, you will have to add your Apple
I.D. here.
So here you're going to put in your e-mail that you use to logon to Apple, and then it's going to prompt
you for your password.
Now once you've successfully logged in with your Apple I.D. then you should now be able to go into the
team selector and select the account that you've just added.
Now because mine is a developer account, it will show up with our company name.
But in your case it should probably be your name, or the email that you use to log in.
So now we're finally ready to connect your phone with USB. So hook up your phone to your Mac.
And at this moment in time, you'll probably get a popup that ask you whether if you trust this computer
that you connected your phone to. The popup should look something like this.
And even though we're always used to clicking on the right hand side and and always the bolded words,
be sure that you click on 'Trust' over here instead.
Be careful that you actually click on the right one.
Now if you accidentally clicked on the one on the right, then be sure to unplug your phone and re-plug
it to hopefully read trigger these popup, and trust it.
Now there's one more thing that we have to trust, which is our development certificates. So it's the
Apple I.D. that we added just now in Xcode. And the easiest way to get this to trigger, is to actually
click Run inside Xcode to try and run it on to your physical devices.
If your device that's currently connected is not showing up right here,
make sure that the team is selected, and make sure that you've had a look inside this drop down and you've
been able to select the device.
Now you can click Run, and after you run it from Xcode,
If your app doesn't automatically launch on your iPhone, then it's time to go into your settings, go under
general, and then try and find device management, to find your Apple I.D. and then click on 'trust' to trust
your developer I.D. And once that's done, you should be able to come back to Xcode, run it again and
it should now go through without a problem.
Now the final thing we have to do here in Xcode, is to create a unique bundle I.D. That means you have
to make sure you've got the Runner app selected, you're inside the targets of runner,
you've got general selected, and this is your bundle identifier.
So here we've got our domain here appbrewere.co reversed.
So usually what we tell students is to write com, and then write your name, and then it should have .
the name of the app.
And this,
hopefully nobody with your full name is trying to release an app called 'I Am Rich'
onto the app store. And this will work just fine.
Now if you don't have this unique, usually you'll have a little red warning around here, and it will not
let you run your app until you fix this.
So after all of those steps, we're finally ready to tackle the very last one, which is being able to
run your app from Android Studio.
So head back into Android Studio, and at this point before we try and run our app on our physical iPhone,
it's a good idea to run a final check just to make sure that everything is setup correctly.
For that, we will use our Flutter Doctor. The Flutter Doctor will let us know if there was anything we
missed during the setup process. So go into Tools, and then under Flutter, select Flutter
Doctor. And now it will run the Flutter Doctor diagnostics, and it'll show you what are the things that you've
completed,
what are the things that might still be yet incomplete, and if you see any of these points as a cross,
then it usually includes a link to a documentation on Flutter's docs to tell you how you can fix it. But
now that I've got ticks all across the board, you should see your phone being listed inside this drop down
list, and from now on, every time it's plugged in, you'll see it show up as a potential deployment target,
so you'll be able to run your apps onto your phone, without ever having to do all of the setup that we
did before.
So with our device listed in the dropdown and no issues detected by the Flutter Doctor, we're finally
ready to hit play and run our app on our physical device. And now you can see that the app has been installed
onto my physical device, and it will launch automatically, without you having to click on the app icon.
And is actually quite important that you don't click on the app icon, because that will usually launch
the previous version of your app.
So just wait for Android Studio and Flutter to kickstart the app. And now I have my 'I Am Rich' app running
on my physical iOS device. So there's quite a few steps involved in doing this and there's quite a few
places that students fall down on.
So we've compiled a list for you to troubleshoot any problems you have and just check that you've completed
all of the steps. So that we'll be in the course resources under this module.
And if you have any problems getting up to here, then be sure to check that out.
Now once you already, head over to the next module, and we're going to be building another app.