Skip to content

Instantly share code, notes, and snippets.

@furydeveloper
furydeveloper / FirstViewController.swift
Created January 12, 2020 02:29
FirstViewController.swift
// currentVC => FirstViewController
guard let pvc = self.presentingViewController else { return }
self.dismiss(animated: true) {
pvc.present(SecondViewController(), animated: true, completion: nil)
}
@furydeveloper
furydeveloper / FirstViewController.swift
Last active January 12, 2020 02:22
FirstViewController.swift
// currentVC => FirstViewController
self.dismiss(animated: true) {
self.present(SecondViewController(), animated: true, completion: nil)
}
@furydeveloper
furydeveloper / ViewController.swift
Created January 4, 2020 01:21
ViewController.swift
let phoneNumber = "01012345678"
var firstIndex = phoneNumber.index(phoneNumber.startIndex, offsetBy: 0)
var lastIndex = phoneNumber.index(phoneNumber.startIndex, offsetBy: 3)
let mobCom = "\(phoneNumber[firstIndex..<lastIndex])"
firstIndex = phoneNumber.index(phoneNumber.startIndex, offsetBy: 3)
lastIndex = phoneNumber.index(phoneNumber.endIndex, offsetBy: -4)
let mobNo1 = "\(phoneNumber[firstIndex..<lastIndex])"
@furydeveloper
furydeveloper / AppDelegate.swift
Created November 11, 2019 16:26
AppDelegate.swift
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
let dataDict: [String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("[Log] didReceive :", messaging)
}
@furydeveloper
furydeveloper / AppDelegate.swift
Created November 11, 2019 16:10
AppDelegate.swift
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
}
@furydeveloper
furydeveloper / AppDelegate.swift
Created November 11, 2019 10:45
AppDelegate.swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print("[Log] deviceToken :", deviceTokenString)
Messaging.messaging().apnsToken = deviceToken
}
@furydeveloper
furydeveloper / AppDelegate.swift
Last active November 11, 2019 10:49
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, _ in }
application.registerForRemoteNotifications()
@furydeveloper
furydeveloper / SceneDelegate.swift
Created November 6, 2019 03:51
SceneDelegate.swift
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: userIdentifier) { (credentialState, error) in
switch credentialState {
case .authorized:
// The Apple ID credential is valid. Show Home UI Here
break
case .revoked:
// The Apple ID credential is revoked. Show SignIn UI Here.
break
case .notFound:
@furydeveloper
furydeveloper / LoginViewController.swift
Last active November 5, 2019 14:17
LoginViewController.swift
extension ViewController: ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
// Create an account in your system.
let userIdentifier = appleIDCredential.user
let userFirstName = appleIDCredential.fullName?.givenName
let userLastName = appleIDCredential.fullName?.familyName
let userEmail = appleIDCredential.email
//Navigate to other view controller
@furydeveloper
furydeveloper / LoginViewController.swift
Created November 5, 2019 14:02
LoginViewController.swift
func performExistingAccountSetupFlows() {
// Prepare requests for both Apple ID and password providers.
let requests = [ASAuthorizationAppleIDProvider().createRequest(),
ASAuthorizationPasswordProvider().createRequest()]
// Create an authorization controller with the given requests.
let authorizationController = ASAuthorizationController(authorizationRequests: requests)
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()