Skip to content

Add Community Supported tvOS #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jan 3, 2018
Merged

Add Community Supported tvOS #590

merged 27 commits into from
Jan 3, 2018

Conversation

paulb777
Copy link
Member

Add Community Supported tvOS for Core, Auth, Database and Storage.
Add tvOS unit tests
Add tvOS sample app
Update README.md
Add tvOS to travis testing

ryanwilson and others added 20 commits November 13, 2017 13:32
Initial tvOS project sample.
* Core Unit Tests for tvOS

* tvOS 10 and shared schemes

* copyrights

* style fixes
* Example using Firebase Storage.

* Remove unnecessary AppDelegate methods

* Fixed comment on constants
* Build and unit test Database for tvOS

* delete blank line
* Build environment for tvOS Auth

* Added Auth example for email and password sign in.

* Fixed TARGET_OS_TV check

* Cleaned up storyboard
Copy link
Member

@ryanwilson ryanwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exciting! It'll be great to get Firestore support too if possible. LGTM, will wait to see what the others think.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome! I have some question about the Storage and Database sample.

import UIKit
import FirebaseDatabase

/// A class to demonstrate the power of the Firebase Realtime Database. This will show a number read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would prefer if this just read "A class to demonstrate the Firebase Realtime Database API."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// MARK: - Internal Helpers

/// Update the number on the server by a particular value. Note: the number passed in should only
/// be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// be
private func changeServerValue(with type: Counter) {
let ref = Database.database().reference(withPath: Constants.databasePath)
// Update the current value of the number!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Remove "!"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return TransactionResult.abort()
}

currentData.value = value + type.rawValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't write much Swift, but it seems a little strange to me to use the index value of an enum in a computation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used enums a bit like this since they're a lot more flexible and not limited to just a raw value anymore. It could be expanded in the future to have different values, it just saves the switch statement.

I added an intValue calculated property that returns the rawValue internally, so it's more of an implementation detail as opposed to relying on the functionality externally. Does that make more sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does. Thanks for cleaning this up.


// We could have the image cached already causing the completion block to run before this line.
// If that's the case, we don't need to do anything else and can return.
if case .downloaded = state { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firebase Storage doesn't have a cache. Can you explain what is going on here? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, interesting. There were a few situations where if you already downloaded the photo + cleared it, the completion block setting the state to downloaded would be triggered before the code afterward setting it to downloading. Maybe this is Apple's caching under the hood?

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be using an NSURLCache by default, but even with that I would be surprised that this code would race. There might be something else going on here, but I am not quite sure what it could be.
Either way, please remove the word "cache" from the comment so that our users don't get any wrong ideas :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks!

// Start the download!
let storage = Storage.storage()
let ref = storage.reference(withPath: Constants.downloadPath)
let task = ref.getData(maxSize: Constants.maxSize) { [unowned self] (data, error) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we showcase how to display progress updates as well?


// We could have the image cached already causing the completion block to run before this line.
// If that's the case, we don't need to do anything else and can return.
if case .downloaded = state { return }
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be using an NSURLCache by default, but even with that I would be surprised that this code would race. There might be something else going on here, but I am not quite sure what it could be.
Either way, please remove the word "cache" from the comment so that our users don't get any wrong ideas :)

@@ -73,7 +73,9 @@ - (void)getTokenWithCallback:(FIRAuthAPNSTokenCallback)callback {
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#if !TARGET_OS_TV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using #if TARGET_OS_IOS here as this should only be used for the iOS platform.
I also suspect that this check might not be needed as an APNS token manager should only instantiated on the Auth instance for iOS targets. Did you find this check necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! The check is necessary since UIApplication doesn't have a registerForRemoteNotificationTypes: method available in tvOS so this fails to compile unless it's wrapped.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha :) thanks for the background.


Auth.auth().signIn(withEmail: email, password: password) { [unowned self] (user, error) in
guard let user = user else {
print("Error retrieving user: \(error!)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Error signing in" seems more fitting here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, done.

return nil
}

guard let userPassword = password.text, userPassword.count > 2 else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firebase Auth backend currently enforces a minimum password length of 6 characters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

/// Validate the inputs for user email and password, returning the username and password if valid,
/// otherwise nil.
private func validatedInputs() -> (email: String, password: String)? {
guard let userEmail = emailAddress.text, userEmail.count > 3 else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Firebase Auth backend does email validation, you may want to rely on the backend validation in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, I figured this way if someone just tries to hit "Go" without typing anything in, we'd throw up an error before bothering the backend. In a real scenario I'd probably highlight this in the UI, etc but this was a quick fix. I can remove it entirely but I don't think it hurts having it here, since it's more of a pre-validation than a full validation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. We refrain from doing validation on the client because it's easier and faster to update the server if needs be. Makes total senses to save the round trip in a sample app.


Auth.auth().createUser(withEmail: email, password: password) { [unowned self] (user, error) in
guard let user = user else {
print("Error retrieving user: \(error!)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Error signing up" seems more fitting here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Done

@paulb777 paulb777 merged commit f08b504 into master Jan 3, 2018
@paulb777 paulb777 deleted the pb-merge-tvOS branch January 3, 2018 20:12
@paulb777 paulb777 mentioned this pull request Jan 3, 2018
@mariohahn
Copy link

😍

zxu123 pushed a commit that referenced this pull request Jan 8, 2018
* Update CHANGELOG for macOS AppKit dependency. (#609)

* Add Community Supported tvOS (#590)

Add Community Supported tvOS for Core, Auth, Database and Storage.
Add tvOS unit tests
Add tvOS sample app
Update README.md
Add tvOS to travis testing

* Adds API Test for Email Update (#613)

* update Gemfile for Travis (#620)

* update Travis to Xcode 9.2 (#619)

* Removing an obsolete setting from plist files (#617)

* Removing an obsolete setting from plist files

* Fixing Unit Tests

* Fixing nullability

* Fully qualify protoc-generated outputs (#626)

* Fully-qualify imports in the protocol compiler output

* pbxproj updates from running pod update

* New checked-in proto outputs

* Port StringPrintf from //base (#624)

* Port StringPrintf from //base.

  Prefer this to approaches based on variadic templates. While the variadic
  template mechanisms are strictly safer, they result in binary bloat we
  can't afford.

  This is essentially the same StringPrintf previously open sourced as a
  part of protobuf, though updated for C++11 which saves a copy and a
  temporary buffer on the heap.

* Add abseil as a subdirectory of Firestore

  This saves having to redefine all the libraries that abseil defines as
  imported libraries.

* Rename firebase_firesture_util_log_* targets

  Cut the log out of the name to reflect that these will get more
  components besides just logging.

* Update tests for firebase_firestore_util renames
minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this pull request Jun 6, 2018
Add Community Supported tvOS for Core, Auth, Database and Storage.
Add tvOS unit tests
Add tvOS sample app
Update README.md
Add tvOS to travis testing
@firebase firebase locked and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants