Skip to content

Instantly share code, notes, and snippets.

View elpsk's full-sized avatar
:octocat:
I may be slow to respond.

alberto elpsk

:octocat:
I may be slow to respond.
View GitHub Profile
@elpsk
elpsk / voiceOver
Created September 28, 2018 10:26
Swift - Voice over detection
//
// VoiceOverVC.swift
// Created by Pasca Alberto, IT on 10/08/18.
// Copyright © 2018 albertopasca.it. All rights reserved.
//
import UIKit
class VoiceOverVC: UIViewController {
@elpsk
elpsk / lowpower
Created September 28, 2018 10:25
Swift - detect low power
//
// LowPowerVC.swift
// Created by Pasca Alberto, IT on 10/08/18.
// Copyright © 2018 albertopasca.it. All rights reserved.
//
import UIKit
class LowPowerVC: UIViewController {
@elpsk
elpsk / pasteboard
Created September 28, 2018 10:25
Swift - pasteboard
//
// PasteboardVC.swift
// Created by Pasca Alberto, IT on 10/08/18.
// Copyright © 2018 albertopasca.it. All rights reserved.
//
import UIKit
class PasteboardVC: UIViewController {
@elpsk
elpsk / proximity
Last active May 19, 2023 17:07
Swift - Proximity sensor (shut down screen if near ear)
//
// ProximityVC.swift
// Created by Pasca Alberto, IT on 10/08/18.
// Copyright © 2018 albertopasca.it. All rights reserved.
//
import UIKit
class ProximityVC: UIViewController {
@elpsk
elpsk / fontsize.swift
Created September 28, 2018 10:23
Swift - Detect device font size
//
// FontSizeVC.swift
// Created by Pasca Alberto, IT on 10/08/18.
// Copyright © 2018 albertopasca.it. All rights reserved.
//
import UIKit
class FontSizeVC: UIViewController {
@elpsk
elpsk / shake
Created September 28, 2018 10:21
Swift - Undo text using Shake
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
if motion == .motionShake {
if (<#textField#>.undoManager?.canUndo)! {
self.<#textField#>.undoManager?.undo()
}
}
}
@elpsk
elpsk / Brightness
Created September 28, 2018 10:20
Swift - Brightness
import UIKit
class BrightnessVC: UIViewController {
var timer: Timer?
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { (t) in
@elpsk
elpsk / screenshot
Created September 28, 2018 10:19
Swift - detect a screenshot
func screenshotDetector() {
NotificationCenter.default.addObserver(forName: .UIApplicationUserDidTakeScreenshot, object: nil, queue: OperationQueue.main) { notification in
print("Screenshot taken!")
}
}
@elpsk
elpsk / Headphones
Created September 28, 2018 10:19
Swift - detect plugged headphones
import AVFoundation
import MediaPlayer
// [...]
private func headphones() {
let currentRoute = AVAudioSession.sharedInstance().currentRoute
if currentRoute.outputs.count != 0 {
for description in currentRoute.outputs {
@elpsk
elpsk / BatteryStatus.swift
Created September 28, 2018 10:17
Swift - Battery status
import UIKit
class BatteryVC: UIViewController {
var timer: Timer?
override func viewDidLoad() {
super.viewDidLoad()
UIDevice.current.isBatteryMonitoringEnabled = true