設定画面追加

1 parent ff197085
...@@ -8,19 +8,73 @@ ...@@ -8,19 +8,73 @@
8 8
9 import UIKit 9 import UIKit
10 10
11 class DemoView: UIView { 11 class DemoView: UIView, UITextFieldDelegate {
12 12
13 13
14 // Only override draw() if you perform custom drawing. 14 // Only override draw() if you perform custom drawing.
15 // An empty implementation adversely affects performance during animation. 15 // An empty implementation adversely affects performance during animation.
16
17 let label = UILabel()
18 let textbox_distance_fillter = UITextField()
19 let button_distance_fillter = UIButton()
20
16 override func draw(_ rect: CGRect) { 21 override func draw(_ rect: CGRect) {
22 Caller.sheardInstance.setProximityNofitication(proximityFillter:50)
23 textbox_distance_fillter.text = "50"
17 // Drawing code 24 // Drawing code
18 let label = UILabel() 25 label.text = " Demo "
19 label.text = "Demo"
20 label.sizeToFit() 26 label.sizeToFit()
21 self.addSubview(label) 27 self.addSubview(label)
28 ///////
29
30 let tWidth: CGFloat = 200
31 let tHeight: CGFloat = 40
32 let posX: CGFloat = (self.bounds.width - tWidth)
33 let posY: CGFloat = (self.bounds.height - tHeight)
34
35
36 //////
37 textbox_distance_fillter.keyboardType = .numberPad
38 // textbox_distance_fillter.sizeToFit()
39 textbox_distance_fillter.frame = CGRect(x: (posX/6), y: (posY/12), width: tWidth,height: tHeight)
40 textbox_distance_fillter.delegate = self
41 // 枠を表示する.
42 textbox_distance_fillter.borderStyle = .roundedRect
43
44 self.addSubview(textbox_distance_fillter)
45 ///////
22 46
47 ///////
48 button_distance_fillter.addTarget(self, action: #selector(setDistanceFillter), for:.touchUpInside)
49 button_distance_fillter.frame = CGRect(x: (posX/6), y: (posY/6), width: tWidth, height: tHeight)
50 button_distance_fillter.setTitle("fillter", for: .normal)
51
52 button_distance_fillter.setBackgroundImage(self.createImageFromUIColor(color: UIColor.gray), for: .normal)
53 button_distance_fillter.setBackgroundImage(self.createImageFromUIColor(color: UIColor.lightGray), for: .highlighted)
54
55 button_distance_fillter.setTitleColor(UIColor.white, for: .normal)
56 self.addSubview(button_distance_fillter)
57 ///////
58 }
59 func setDistanceFillter(sender: UIButton){
60 if let fillter = textbox_distance_fillter.text{
61 if let distanceF = Int(fillter){Caller.sheardInstance.setProximityNofitication(proximityFillter:distanceF)
62 self.endEditing(true)
63 }
64 }
65 }
66 private func createImageFromUIColor(color: UIColor) -> UIImage {
67 // 1x1のbitmapを作成
68 let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
69 UIGraphicsBeginImageContext(rect.size)
70 let context = UIGraphicsGetCurrentContext()
71 // bitmapを塗りつぶし
72 context!.setFillColor(color.cgColor)
73 context!.fill(rect)
74 // UIImageに変換
75 let image = UIGraphicsGetImageFromCurrentImageContext()
76 UIGraphicsEndImageContext()
77 return image!
23 } 78 }
24
25 79
26 } 80 }
......
...@@ -267,7 +267,7 @@ BleControl *cv; ...@@ -267,7 +267,7 @@ BleControl *cv;
267 267
268 [protocol parseData:data length:length]; 268 [protocol parseData:data length:length];
269 /* for iot Demo */ 269 /* for iot Demo */
270 [[Caller sheardInstance] proximityNofitication :[SenserData sheardInstance].proximity ]; 270 [[Caller sheardInstance] proximityNofiticationTrigger];
271 /* for iot Demo end */ 271 /* for iot Demo end */
272 } 272 }
273 273
......
...@@ -8,48 +8,62 @@ ...@@ -8,48 +8,62 @@
8 8
9 import Foundation 9 import Foundation
10 import UIKit 10 import UIKit
11 import CoreAudioKit
11 import UserNotifications 12 import UserNotifications
13
14
12 class Caller:NSObject{ 15 class Caller:NSObject{
13 public static let sheardInstance:Caller = Caller() 16 public static let sheardInstance:Caller = Caller()
14 17
15 public func proximityNofitication(_ data:Int){ 18 var proximityFillter:Int = 50
16 if(data > 100 ){return} 19 public func setProximityNofitication(proximityFillter:Int){
17 if #available(iOS 10.0, *) { 20 self.proximityFillter = proximityFillter
18 NSLog("yobareta"); 21 }
19 UserNofitication.sharedInstance.easyNofitication( 22 public func proximityNofiticationTrigger(){
20 /* nofitication detail */ 23 NSLog("SenserData.sheardInstance.proximity")
21 identifier : "nofity", 24 if let proximity = SenserData.sheardInstance.proximity{
22 title : "データが届きました", 25 NSLog(String(proximity))
23 body : String(data) + "cm", 26 proximityNofitication(proximity,fillter:proximityFillter)
24 actions : [ 27 }
25 UNNotificationAction( 28
26 identifier: "possitive", 29 }
27 title: "", 30 private func proximityNofitication(_ data:Int?, fillter:Int){
28 options:[])], completionHandler: ({(Error)->Void in 31 if let data = data {
32 if(data > fillter ){return}
33 if #available(iOS 10.0, *) {
34 UserNofitication.sharedInstance.easyNofitication(
35 /* nofitication detail */
36 identifier : "nofity",
37 title : "データが届きました",
38 body : String(data) + "cm",
39 actions : [
40 UNNotificationAction(
41 identifier: "possitive",
42 title: "",
43 options:[])], completionHandler: ({(Error)->Void in
29 44
30 }), 45 }),
31 46
32 /* response callback */ 47 /* response callback */
33 response : UNResponseManager.sharedInstance.setResponse(identifier: "nofity") {(_ actionIdentifier:String) in 48 response : UNResponseManager.sharedInstance.setResponse(identifier: "nofity") {(_ actionIdentifier:String) in
34 switch actionIdentifier { 49 switch actionIdentifier {
35 case "positive": 50 case "positive":
36 51 break
37 52 case UNNotificationDismissActionIdentifier:
38 break 53 /* 選択せずにnofiticationを消去の場合*/
39 case UNNotificationDismissActionIdentifier: 54 break
40 /* 選択せずにnofiticationを消去の場合*/ 55 case UNNotificationDefaultActionIdentifier:
41 break 56 /* 選択せずにアプリ起動場合*/
42 case UNNotificationDefaultActionIdentifier: 57 break
43 /* 選択せずにアプリ起動場合*/ 58 default:
44 break 59 break
45 default: 60 }
46 break 61 })
47 } 62 } else {
48 }) 63 // Fallback on earlier versions
49 } else { 64 }
50 // Fallback on earlier versions 65 }
51 } 66 }
52 }
53 67
54 public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 68 public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
55 69
...@@ -57,7 +71,7 @@ public func application(_ application: UIApplication, didFinishLaunchingWithOpti ...@@ -57,7 +71,7 @@ public func application(_ application: UIApplication, didFinishLaunchingWithOpti
57 let center = UNUserNotificationCenter.current() 71 let center = UNUserNotificationCenter.current()
58 center.requestAuthorization(options: [.alert], completionHandler: { (granted, error) in 72 center.requestAuthorization(options: [.alert], completionHandler: { (granted, error) in
59 if error != nil { 73 if error != nil {
60 print(error?.localizedDescription) 74 print(error?.localizedDescription as Any)
61 return 75 return
62 } 76 }
63 }) 77 })
......
...@@ -12,7 +12,7 @@ class SenserData:NSObject{ ...@@ -12,7 +12,7 @@ class SenserData:NSObject{
12 public static let sheardInstance:SenserData = SenserData() 12 public static let sheardInstance:SenserData = SenserData()
13 13
14 public var data:String = "1" 14 public var data:String = "1"
15 public var proximity:Int = 0 15 public var proximity:Int?
16 16
17 17
18 public func setData(_ type:String,data:String){ 18 public func setData(_ type:String,data:String){
......
...@@ -23,6 +23,7 @@ class UserNofitication:NSObject{ ...@@ -23,6 +23,7 @@ class UserNofitication:NSObject{
23 ){ 23 ){
24 24
25 25
26
26 let category = UNNotificationCategory(identifier: identifier, 27 let category = UNNotificationCategory(identifier: identifier,
27 actions: actions , 28 actions: actions ,
28 intentIdentifiers: [], 29 intentIdentifiers: [],
...@@ -43,6 +44,11 @@ class UserNofitication:NSObject{ ...@@ -43,6 +44,11 @@ class UserNofitication:NSObject{
43 content: content, 44 content: content,
44 trigger: trigger) 45 trigger: trigger)
45 let center = UNUserNotificationCenter.current() 46 let center = UNUserNotificationCenter.current()
47
48 center.requestAuthorization(options: [.alert, .badge, .sound]) { (val,err) in
49
50 }
51
46 center.delegate = UNResponseManager.sharedInstance 52 center.delegate = UNResponseManager.sharedInstance
47 center.add(request, withCompletionHandler:completionHandler) 53 center.add(request, withCompletionHandler:completionHandler)
48 54
......