[Music]
hello everyone and welcome
my name is ryan and i'm a software
engineer on the firebase team
working on apple sdks in our waterloo
canada office
and i'm chen i am a soft engineer on the
firebase team
also working on apple sdks i'm based in
sunnyvale
california office firebase's mission is
to help developers succeed by making it
easy to build
and operate apps we know that the
firebase is a cross-platform mobile
developer toolkit
supporting ios along with android web
cpa plus and unity
but hey we know why you're here if
you're excited like me
you might find that apple ecosystem has
made it easier to develop multi-platform
apps
not just for ios and ipad os but mac os
watch os tv os and catalyst
that's a long list at firebase we'll
look into some of the use cases here
and making them available across apple's
platforms
the firebase sdk for apple platforms
gives you the flexibility to unlock some
non-ios development flow
and will continue to do more in the
future building and running apps for ios
and other apple platforms
has changed over the past few years
swift has become the de facto language
for building apps
we're going to cover some neat swift
language features and frameworks in this
session
swift ui for example allows us to build
beautiful
interfaces using a simple and concise
syntax
swift package manager makes it easier
than ever to include firebase sdks in
your project
async await and combine are new ways we
can reason about asynchronous
programming at firebase we're watching
these changes closely
and today we'll show you how we're
approaching these changes in the
ecosystem
but first chen what's going on in our
github repo
let me tell you ryan since firebase took
the first step of
open sourcing our client libraries in
2017
the vast majority of firebase sdk for
apple platforms are available today on
github
we recently open sourced the firebase
performance sdk at the end of 2020 so in
case you haven't seen it yet
go check it out and let us know what you
think we'll continue to show our
commitment of greater transparency and
building a stronger developer community
to this day we've closed over 2000
issues and merged over 5000 pull
requests
our firebase team loves the interaction
with you on github
we encourage you to voice your feedback
no matter their feature requires or
bargain issues
because you can talk directly to our
engineers who build on the sdks
including ryan me it also make the
technical conversations
much easier we have been fortunate to
have an amazing community of
contributors
there are currently 139 of you
contributing on firebase sdk for apple
platforms
we're seeing an active open source
collaborations between the community
members and firebasers
working together on combined support we
want to give you a big thank you
to all of you for making our sdks better
being open source has made many things
possible
being able to step through the code and
know exactly how your sdk
behaves save hours about countings it
also enables features like
community support for tv os os
catalyst and watch os we recently added
community virtualized support for real
time database and remote config
so now you can try this out in your
watch app and use github discussions to
ask any questions
so many of you have already started
using swift package manager to managing
dependencies
today firebase is officially supporting
swift package manager
so in addition to cocoapods now you can
use swift package manager to add
firebase libraries to your app
here i'll quickly show you how you can
do it because it's really easy
first you need to get the urls from the
firebase ios sdk report page
copy paste the urls from the page this
should work for most libraries that are
hosted on or distributed via github
now open your app in your xcode click on
the file tab
and select the split package then click
on add package dependency
paste the urls and click next select the
version
or branch you want to target we
recommend getting the latest version of
our sdks
not just for the new features but more
importantly for bug fixes and
improvements
shortly after you should be able to
select the product you want to use
here we'll use analytics auth and we
want to try out the new swift ui
extension apis
one thing to know is that if you want to
add it in a different target say you
have an independent watch target
and you only want to install messaging
inside the watch app you can choose a
target on the right side
when you're done click finish then you
should be able to see the packages if
you click project and select swift
package here
if you want to add more firebase sdks
later you can go to the target that you
want to edit
click on general and under the
frameworks libraries and embedded
content
you can manually add firebase sdks or
delete some if you no longer need it
now that we've created a new project
with swift package manager let's hear
from ryan to talk more about swift
and swift ui thanks chen
despite our sdks being written mostly in
objective c
we evaluate every single api to see how
it gets imported into swift
and try to make the experience great but
what about things like result types
codable support
default parameters or enums with
associated types
we can't take advantage of those great
swift features when writing objective c
sometimes we just need to write swift
code that's why we've started shipping
optional swift extensions to different
sdks and some have even been contributed
by the community
let's go over some highlights we're
going to be looking at a lot of code
here's a snippet where we're downloading
a picture from firebase storage
using the traditional completion handler
block both data and error are optional
and that leads to some awkward code
causing us to force unwrap the error
not something we want to do if we can
avoid it the error should always be
populated when data is now
and data should always be nil when
there's an error but we can enforce that
in the compiler using the existing code
by switching to use the function the new
swift extension provided
we can eliminate that awkward state and
the force unwrap
using a switch statement we get the
compiler safety of only having two
states represented
we have data or we have an error no more
in between states
let's move on to firestore and parsing
data this is a shortened code snippet
showing data parsing from a previous
version of our firestore quickstart app
after getting the data from firestore we
want to convert it into a local type
from the dictionary provided
in this case a restaurant does this kind
of code look familiar to you
makes me sad every time i read the
manual unwrapping and airplane string
keys
not taking advantage of swift's type
safety features it's fragile
hard to read and easy to make mistakes
when writing it instead
let's add codable conformance to our
restaurant type by conforming to the
codable protocol
we get a lot of that manual code parsing
for free as is generated by the compiler
and updates stay consistent across the
type
reading that data from firestore is now
as easy as calling the data as function
on document snapshot
and passing in the restaurant type no
more manually parsing that object
codeable does all the work for us
setting the data in firestore is just as
easy
passing in the instance directly instead
of a dictionary representation of it
we also just published a similar api for
firebase database
thanks to an external contributor next
the new
and exciting swift ui this one's my
favorite
i'm excited to share we recently shipped
some swift ui specific apis with more to
come
at wwdc 2020 we were introduced to a new
swift ui app lifecycle that's shared
across platforms
previously we recommended you put
firebase app.configure at the top of
your app did finish launching call in
your app delegate
well where does it go if there's no app
delegate
we simply override the init function
that gets called when an app starts
and call firebase app.configure there
this remains true
even if you need to use a ui application
delegate adapter
to handle things like push notifications
which we'll see later on in a demo from
chen the first new api i wanted to show
you
is for logging manual screen view events
in google analytics for firebase
there are existing apis to automatically
record screen views and screen classes
for ui kit
but due to the fact swift ui does not
have a corresponding ui view controller
that we can tap
into that doesn't work when using swift
ui
thankfully last year we added a manual
screen view event
so you could have careful control over
when these events were logged
and that fits in well when writing you
on kit integrating this into your viewed
it appear
it stays mostly out of the way let's
take a look at what this looks like in
swift ui
we can call these manual logging apis
whenever a view appears using the on
appear modifier
so this works but it's pretty verbose
and can clutter your code and take away
from the structure of your view
we're at our limit with what we can
offer from an api standpoint in
objective c
but we can do better in swift this looks
like a great opportunity for a custom
view modifier
and that's exactly what we built we can
now mark up any view with the provided
analytics screen view modifier
to declare the name of the view the
class or in this case the struct
but we're matching existing analytics
naming here and any extra parameters
you'd like to be logged when this view
appears on screen
and thanks to swift's default arguments
you can provide just the name and the
rest is
optional like in this case where we're
leaving out the extra parameters
argument
we are really excited about this new way
to mark up your views and record screen
view events
another swift ui improvement we shipped
is for building your own
in-app message views in this example
we're using the modal in-app message
modifier
the closure is a view builder and the
arguments are the message which contains
the data that was configured in the
console
plus the delegate to notify the in-app
messaging sdk
of interactions like when a message is
tapped or dismissed
in order to record metrics and
impressions there are apis covering each
message type that make providing custom
interfaces
from your in-app messages easier than
ever let us know in a github discussion
if you have any ideas for other swift ui
helpers you'd like to see
the community is excited about combined
and we can't blame them we are too
we've received some amazing
contributions from the folks in the
community
and have been working on some changes
ourselves there's still a lot of work to
do in this space
but here's a sneak peek at what you can
expect this is the publisher we wrote
for auths
sign in using an email and password it
returns a combined future
of the auth data result or the
associated error
this is a bit simplified but in this
pipeline we are extracting the user
replacing any errors with nil and
assigning it to our signed in user
property
that gets represented in the ui we've
got multiple publishers across different
sdks to help you with your async data
flow
you can keep an eye on progress in our
combined apis using the github project
we have set up
combined isn't the only exciting
progress made on async handling code
we're very close to seeing async await
in a released version of the swift tool
chain
let's take another look at sign in with
email and password this time comparing
the completion handler
to async await here we use completion
handlers to handle the control flow
inside of that completion handler we may
want to do more asynchronous calls
which can lead to the classic pyramid of
doom
how does async await transform this call
instead of having to manage the state
entirely in the completion handler block
it looks more like synchronous code and
is easier to reason about
we can continue to do the same for other
async calls and it's going to be
far simpler to maintain state and make
sure errors are handled appropriately
now i'd like to pass it back to chen for
an exciting demo
thanks ryan now let's talk a bit about
how you can build an independent
workshop with firebase
say you would like to track your daily
coffee intakes on your watch
one cool thing about an independent
watch app is that the users can use it
without the need to sync from their
phones
firebase is working on making watch app
development easier by connecting
watch directly to firebase cloud service
currently we have several products that
have community support for watch os
so that you can for example send push
notifications from the firebase console
directly to your watch app
sync your copy intake progress with a
real-time database
without a companion phone or download
the image from cloud storage directly to
your watch one thing to know is that the
apps you set up on the console
should be one-on-one matching of the
apps in app store connect
if app covers multiple platforms use a
single firebase app and google service
info please
for all the platforms that app runs them
this applies to ios app extensions as
well
for example if your app has an ios app a
mac app
and a widget target you can simply
import the main app's google service
info please file to all targets
now that you've set up your firebase
project successfully and import the
please file to xcode
let's come back to how we can send push
notifications directly to your watch app
we're using the latest swift ui
lifecycle here so you'll notice
there's no extension delegate available
this is because a swift ui lifecycle
by default does not include any app or
extension type delegate
what you can do here is to use wk
extension delegate adapter
to inject the delegate to your app where
you can add code
to request virtualized push notification
permissions and handle any firebase sdks
api
that require app delegate to exist for
this case you need to set the apn's
token to messaging sdk
in the past this step was handled
automatically by messaging when
swizzling was enabled
however as switzerland has become more
fragile we no longer recommend this
approach on watch os
instead you will need to implement a did
register for remote notifications method
from the wk extension delegate to
manually set the apn's token to
messaging
the same applies to the ios app if you
use a swift ui lifecycle
you'll need to use the ui application
delegate adapter to inject your own app
delegate from the ui kit
then you can implement code that
requires app delegate to exist
now let me show you a snippet of code on
how you can download the qsparky image
directly to your watch app
we're using the firebase storage here oh
did you notice the exact same code can
run on your ios app as well
yes because firebase storage does not
require a special watch key api like
messaging
you can have almost identical code for
your watch os
ios tv os and mac os apps
we also unlock some app extension
support because they're really helpful
making it easier
for your users to access your app and do
more fun things take widget
as an example widget extension is a
great way of presenting your app
information and making it more appealing
for users to click on
here's a code snippet where you can pull
pictures using storage
to your widget extension and with that
you get a sparky running on your widget
kit as well
and it's a great way to show some key
info of your app to the users
instead of basic icon which is pretty
cool and that's it
we hope you had a great time building
apple apps with us definitely check out
our github ripple
there's a lot of useful information you
can find there try it out
file bugs and start github discussions
we can't wait to see what you can build
with firebase