Skip to content

Instantly share code, notes, and snippets.

View fredriccliver's full-sized avatar
🧭
To the north

Fredric Cliver fredriccliver

🧭
To the north
View GitHub Profile
// ...
import CoreData
import AVFoundation
// ...
class ViewController: UIViewController {
// ...
var coreDataContext:NSManagedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
// ...
// ...
import CoreData
// ...
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
const updateUrlParams = () => {
const currentLocale = 'en-GB'
var url = new URL(window.location.href)
// searchParam : https://usefulangle.com/post/81/javascript-change-url-parameters
url.searchParams.set('lang', currentLocale)
// pushState : https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
import firebase from "firebase/app"
if (location.hostname == "127.0.0.1" || location.hostname == "localhost") {
console.log("This is local emulator environment")
firebase.functions().useFunctionsEmulator("http://localhost:5001")
}else{
console.log("It is not under emulator environment")
}
firebase
.app()
.functions(functionsRegion())
.httpsCallable("myFunction")(params)
.then((result) => {
// done
})
.catch((error) => {
// error
})
export const functionsRegion = () => {
if (location.hostname == "127.0.0.1" || location.hostname == "localhost") {
return undefined
} else {
return "europe-west1"
}
}
@IBAction func onClickSignOut(_ sender: UIButton) {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
} catch let signOutError as NSError {
print ("Error signing out: \(signOutError.localizedDescription)")
}
}
//
// Created by Fredric Cliver on 2020/10/13.
//
import UIKit
import Firebase
import GoogleSignIn
import CryptoKit
import AuthenticationServices
// cf. https://swiftsenpai.com/xcode/asauthorizationappleidbutton-in-storyboard/
import UIKit
import AuthenticationServices
@IBDesignable
class MyAuthorizationAppleIDButton: UIButton {
private var authorizationButton: ASAuthorizationAppleIDButton!
let toast = new toastMessage.UI("#toast-message-template")
toast.showToast()