Skip to content

Instantly share code, notes, and snippets.

View scott-lydon's full-sized avatar

Scott scott-lydon

  • High Five
  • Burlingame
View GitHub Profile
@scott-lydon
scott-lydon / Optional+Require.swift
Last active March 26, 2018 03:15
RegisterForRemoteNotifications function
//Here starts the function definition and scope
func registerForPushNotifications() {
//Here we are creating a notifCenter reference for shorter lines of code
let notifCenter = UNUserNotificationCenter.current()
//Here we access the requestAuthorization method that lives on the
//UNUserNotificationCenter. It takes an array of options of an enum type
//and a closure as arguments.
notifCenter.requestAuthorization(options: [.alert, .sound, .badge]) {
@scott-lydon
scott-lydon / Optional+Require.swift
Last active November 23, 2018 17:01
AppDelegate call to registerFor Remote Notifications
//The following line should already be present in your AppDelegate.swift file
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Here is the call! Add the next line! It is recommended to ensure the registration is placed on the main thread.
DispatchQueue.main.async {
self.registerForPushNotifications()
}
//This should already be here
return true
@scott-lydon
scott-lydon / Optional+Require.swift
Last active March 26, 2018 03:14
try to register for push notifications
func getNotificationSettingsThenRegister() {
UNUserNotificationCenter.current().getNotificationSettings {
//This closure definition gets access to push notification settings
settings in
//Here we check if the user authorized push notifications
//If the user refused push notification auth, then this will exit early
guard settings.authorizationStatus == .authorized else {return}
//We pop the registration code onto the main queue as recommended by Apple
//This function is called when you successfully registered for remote notifs
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//This is one way we can convert the device token data into a String.
//apns stands for Apple Push Notification Services
let apnsDeviceToken = deviceToken.map {String(format: "%02.2hhx", $0)}.joined()
print(apnsDeviceToken)
}
@scott-lydon
scott-lydon / Optional+Require.swift
Created March 26, 2018 03:31
did fail to register
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
//This function will be called when your attempt to register fails some how.
}
import UIKit
import PPUIElementModules91
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print(weMadeIT)
print(weDidItAgain)
}
import Foundation
public var hello: String = "Holy moly we did it!"
@scott-lydon
scott-lydon / podFont.swift
Created May 31, 2018 16:45
Get fonts from CocoaPods
public final class Fonts {
static func podFont(name: String, size: CGFloat) -> UIFont {
//Why do extra work if its available.
if let font = UIFont(name: name, size: size) {return font}
let bundle = Bundle(for: Fonts.self) //get the current bundle
let url = bundle.url(forResource: name, withExtension: "ttf")! //get the bundle url
let data = NSData(contentsOf: url)! //get the font data
let provider = CGDataProvider(data: fontData)! //convert the data into a provider
@scott-lydon
scott-lydon / podFont.swift
Created May 31, 2018 16:45
Get fonts from CocoaPods
public final class Fonts {
static func podFont(name: String, size: CGFloat) -> UIFont {
//Why do extra work if its available.
if let font = UIFont(name: name, size: size) {return font}
let bundle = Bundle(for: Fonts.self) //get the current bundle
let url = bundle.url(forResource: name, withExtension: "ttf")! //get the bundle url
let data = NSData(contentsOf: url)! //get the font data
let provider = CGDataProvider(data: fontData)! //convert the data into a provider
LM-SJN-21004935:consumer-blank-ios slydon$ git pull upstream develop --rebase
remote: Counting objects: 6388, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 6388 (delta 3638), reused 3639 (delta 3637), pack-reused 2743
Receiving objects: 100% (6388/6388), 7.98 MiB | 4.46 MiB/s, done.
Resolving deltas: 100% (4828/4828), completed with 827 local objects.
From https://github.blank.com/IOS-R/consumer-blank-ios
* branch develop -> FETCH_HEAD
f7c8e8d86a..75b1fa983e develop -> upstream/develop
First, rewinding head to replay your work on top of it...