This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func uploadFile( | |
name: String, | |
folderID: String, | |
fileURL: URL, | |
mimeType: String, | |
service: GTLRDriveService) { | |
let file = GTLRDrive_File() | |
file.name = name | |
file.parents = [folderID] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createFolder( | |
name: String, | |
service: GTLRDriveService, | |
completion: @escaping (String) -> Void) { | |
let folder = GTLRDrive_File() | |
folder.mimeType = "application/vnd.google-apps.folder" | |
folder.name = name | |
// Google Drive folders are files with a special MIME-type. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getFolderID( | |
name: String, | |
service: GTLRDriveService, | |
user: GIDGoogleUser, | |
completion: @escaping (String?) -> Void) { | |
let query = GTLRDriveQuery_FilesList.query() | |
// Comma-separated list of areas the search applies to. E.g., appDataFolder, photos, drive. | |
query.spaces = "drive" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GoogleSignIn | |
import GoogleAPIClientForREST | |
import GTMSessionFetcher | |
class ViewController: UIViewController { | |
let googleDriveService = GTLRDriveService() | |
override func viewDidLoad() { | |
// ... | |
GIDSignIn.sharedInstance()?.scopes = [kGTLRAuthScopeDriveFile] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GoogleSignIn | |
class ViewController: UIViewController { | |
// ... | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
/***** Configure Google Sign In *****/ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: GIDSignInDelegate, GIDSignInUIDelegate { | |
// MARK: - GIDSignInDelegate | |
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { | |
// A nil error indicates a successful login | |
googleSignInButton.isHidden = error == nil | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { | |
let sourceApplication = options[.sourceApplication] as? String | |
let annotation = options[.annotation] | |
return GIDSignIn.sharedInstance()?.handle(url, sourceApplication: sourceApplication, annotation: annotation) ?? false | |
} |
NewerOlder