Somes fixes to iOS app

This commit is contained in:
Oleg Kalachev
2018-06-09 20:33:40 +03:00
parent fd262fdb6a
commit 874f206e2a
2 changed files with 22 additions and 3 deletions

View File

@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0</string> <string>1.0</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2</string> <string>3</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>

View File

@@ -10,12 +10,13 @@ import UIKit
import WebKit import WebKit
import SwiftSocket import SwiftSocket
import NotificationBannerSwift import NotificationBannerSwift
import AudioToolbox.AudioServices
class ViewController: UIViewController, WKScriptMessageHandler { class ViewController: UIViewController, WKScriptMessageHandler {
@IBOutlet weak var webView: WKWebView! @IBOutlet weak var webView: WKWebView!
let impactGenerator = UIImpactFeedbackGenerator(style: .medium) let impactGenerator = UIImpactFeedbackGenerator(style: .medium)
let notificationGenerator = UINotificationFeedbackGenerator() let notificationGenerator = UINotificationFeedbackGenerator()
let udpSocket = UDPClient(address:"255.255.255.255", port: 35602) let udpSocket = UDPClient(address: "255.255.255.255", port: 35602)
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@@ -57,7 +58,7 @@ class ViewController: UIViewController, WKScriptMessageHandler {
} else if (message.name == "lowBattery") { } else if (message.name == "lowBattery") {
// Got low battery notification // Got low battery notification
print("Low battery notification") print("Low battery notification")
notificationGenerator.notificationOccurred(.warning) tapticNotify()
} else if (message.name == "notification") { } else if (message.name == "notification") {
// Got notification message // Got notification message
print(message) print(message)
@@ -72,4 +73,22 @@ class ViewController: UIViewController, WKScriptMessageHandler {
} }
} }
} }
func tapticNotify() {
if let feedbackSupportLevel = UIDevice.current.value(forKey: "_feedbackSupportLevel") as? Int {
switch feedbackSupportLevel {
case 2:
// 2nd Generation Taptic Engine w/ Haptic Feedback (iPhone 7/7+)
notificationGenerator.notificationOccurred(.warning)
case 1:
// 1st Generation Taptic Engine (iPhone 6S/6S+)
let peek = SystemSoundID(1519)
AudioServicesPlaySystemSound(peek)
case 0:
// No Taptic Engine
break
default: break
}
}
}
} }