Skip to content
Toggle navigation
Toggle navigation
This プロジェクト
Loading...
サインイン
呉山勝全
/
iot-ucc-demo-ios
Go to a プロジェクト
Toggle navigation
Toggle navigation pinning
プロジェクト
グループ
スニペット
ヘルプ
プロジェクト
アクティビティ
リポジトリ
パイプライン
Graphs
課題
0
マージリクエスト
0
Wiki
Network
new 課題を作成
ビルド
Commits
Issue Boards
ファイル
Commits
Network
Compare
ブランチ
タグ
5b712720
authored
2017-10-16 15:32:03 +0900
by
USER
ファイルを表示
Options
ファイルを表示
タグ
Download
メール用パッチ
プレーンDiff
設定画面追加
1 parent
ff197085
Show whitespace changes
インライン
Side-by-side
Showing
5 changed ファイルs
with
87 additions
and
13 deletions
DemoView.swift
jacket_test_ios/BleSearchViewController.m
jacket_test_ios/Caller.swift
jacket_test_ios/SenserData.swift
jacket_test_ios/UserNofitication.swift
DemoView.swift
ファイルを表示 @
5b71272
...
...
@@ -8,19 +8,73 @@
import
UIKit
class
DemoView
:
UIView
{
class
DemoView
:
UIView
,
UITextFieldDelegate
{
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
let
label
=
UILabel
()
let
textbox_distance_fillter
=
UITextField
()
let
button_distance_fillter
=
UIButton
()
override
func
draw
(
_
rect
:
CGRect
)
{
Caller
.
sheardInstance
.
setProximityNofitication
(
proximityFillter
:
50
)
textbox_distance_fillter
.
text
=
"50"
// Drawing code
let
label
=
UILabel
()
label
.
text
=
"Demo"
label
.
text
=
" Demo "
label
.
sizeToFit
()
self
.
addSubview
(
label
)
///////
}
let
tWidth
:
CGFloat
=
200
let
tHeight
:
CGFloat
=
40
let
posX
:
CGFloat
=
(
self
.
bounds
.
width
-
tWidth
)
let
posY
:
CGFloat
=
(
self
.
bounds
.
height
-
tHeight
)
//////
textbox_distance_fillter
.
keyboardType
=
.
numberPad
// textbox_distance_fillter.sizeToFit()
textbox_distance_fillter
.
frame
=
CGRect
(
x
:
(
posX
/
6
),
y
:
(
posY
/
12
),
width
:
tWidth
,
height
:
tHeight
)
textbox_distance_fillter
.
delegate
=
self
// 枠を表示する.
textbox_distance_fillter
.
borderStyle
=
.
roundedRect
self
.
addSubview
(
textbox_distance_fillter
)
///////
///////
button_distance_fillter
.
addTarget
(
self
,
action
:
#selector(
setDistanceFillter
)
,
for
:
.
touchUpInside
)
button_distance_fillter
.
frame
=
CGRect
(
x
:
(
posX
/
6
),
y
:
(
posY
/
6
),
width
:
tWidth
,
height
:
tHeight
)
button_distance_fillter
.
setTitle
(
"fillter"
,
for
:
.
normal
)
button_distance_fillter
.
setBackgroundImage
(
self
.
createImageFromUIColor
(
color
:
UIColor
.
gray
),
for
:
.
normal
)
button_distance_fillter
.
setBackgroundImage
(
self
.
createImageFromUIColor
(
color
:
UIColor
.
lightGray
),
for
:
.
highlighted
)
button_distance_fillter
.
setTitleColor
(
UIColor
.
white
,
for
:
.
normal
)
self
.
addSubview
(
button_distance_fillter
)
///////
}
func
setDistanceFillter
(
sender
:
UIButton
){
if
let
fillter
=
textbox_distance_fillter
.
text
{
if
let
distanceF
=
Int
(
fillter
){
Caller
.
sheardInstance
.
setProximityNofitication
(
proximityFillter
:
distanceF
)
self
.
endEditing
(
true
)
}
}
}
private
func
createImageFromUIColor
(
color
:
UIColor
)
->
UIImage
{
// 1x1のbitmapを作成
let
rect
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
1
,
height
:
1
)
UIGraphicsBeginImageContext
(
rect
.
size
)
let
context
=
UIGraphicsGetCurrentContext
()
// bitmapを塗りつぶし
context
!.
setFillColor
(
color
.
cgColor
)
context
!.
fill
(
rect
)
// UIImageに変換
let
image
=
UIGraphicsGetImageFromCurrentImageContext
()
UIGraphicsEndImageContext
()
return
image
!
}
}
...
...
jacket_test_ios/BleSearchViewController.m
ファイルを表示 @
5b71272
...
...
@@ -267,7 +267,7 @@ BleControl *cv;
[
protocol
parseData
:
data
length
:
length
];
/* for iot Demo */
[[
Caller
sheardInstance
]
proximityNofitication
:[
SenserData
sheardInstance
].
proximity
];
[[
Caller
sheardInstance
]
proximityNofiticationTrigger
];
/* for iot Demo end */
}
...
...
jacket_test_ios/Caller.swift
ファイルを表示 @
5b71272
...
...
@@ -8,14 +8,29 @@
import
Foundation
import
UIKit
import
CoreAudioKit
import
UserNotifications
class
Caller
:
NSObject
{
public
static
let
sheardInstance
:
Caller
=
Caller
()
public
func
proximityNofitication
(
_
data
:
Int
){
if
(
data
>
100
){
return
}
var
proximityFillter
:
Int
=
50
public
func
setProximityNofitication
(
proximityFillter
:
Int
){
self
.
proximityFillter
=
proximityFillter
}
public
func
proximityNofiticationTrigger
(){
NSLog
(
"SenserData.sheardInstance.proximity"
)
if
let
proximity
=
SenserData
.
sheardInstance
.
proximity
{
NSLog
(
String
(
proximity
))
proximityNofitication
(
proximity
,
fillter
:
proximityFillter
)
}
}
private
func
proximityNofitication
(
_
data
:
Int
?,
fillter
:
Int
){
if
let
data
=
data
{
if
(
data
>
fillter
){
return
}
if
#available(iOS 10.0, *)
{
NSLog
(
"yobareta"
);
UserNofitication
.
sharedInstance
.
easyNofitication
(
/* nofitication detail */
identifier
:
"nofity"
,
...
...
@@ -33,8 +48,6 @@ public func proximityNofitication(_ data:Int){
response
:
UNResponseManager
.
sharedInstance
.
setResponse
(
identifier
:
"nofity"
)
{(
_
actionIdentifier
:
String
)
in
switch
actionIdentifier
{
case
"positive"
:
break
case
UNNotificationDismissActionIdentifier
:
/* 選択せずにnofiticationを消去の場合*/
...
...
@@ -49,7 +62,8 @@ public func proximityNofitication(_ data:Int){
}
else
{
// Fallback on earlier versions
}
}
}
}
public
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplicationLaunchOptionsKey
:
Any
]?)
->
Bool
{
...
...
@@ -57,7 +71,7 @@ public func application(_ application: UIApplication, didFinishLaunchingWithOpti
let
center
=
UNUserNotificationCenter
.
current
()
center
.
requestAuthorization
(
options
:
[
.
alert
],
completionHandler
:
{
(
granted
,
error
)
in
if
error
!=
nil
{
print
(
error
?
.
localizedDescription
)
print
(
error
?
.
localizedDescription
as
Any
)
return
}
})
...
...
jacket_test_ios/SenserData.swift
ファイルを表示 @
5b71272
...
...
@@ -12,7 +12,7 @@ class SenserData:NSObject{
public
static
let
sheardInstance
:
SenserData
=
SenserData
()
public
var
data
:
String
=
"1"
public
var
proximity
:
Int
=
0
public
var
proximity
:
Int
?
public
func
setData
(
_
type
:
String
,
data
:
String
){
...
...
jacket_test_ios/UserNofitication.swift
ファイルを表示 @
5b71272
...
...
@@ -23,6 +23,7 @@ class UserNofitication:NSObject{
){
let
category
=
UNNotificationCategory
(
identifier
:
identifier
,
actions
:
actions
,
intentIdentifiers
:
[],
...
...
@@ -43,6 +44,11 @@ class UserNofitication:NSObject{
content
:
content
,
trigger
:
trigger
)
let
center
=
UNUserNotificationCenter
.
current
()
center
.
requestAuthorization
(
options
:
[
.
alert
,
.
badge
,
.
sound
])
{
(
val
,
err
)
in
}
center
.
delegate
=
UNResponseManager
.
sharedInstance
center
.
add
(
request
,
withCompletionHandler
:
completionHandler
)
...
...
Please
register
or
sign in
to post a コメント