tgios 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTIzZDUyZTdiNGY4ZGQwODBjNTI2ZDk2ZTkyN2NmZTNhNGEzNzI5ZQ==
4
+ ZGI1N2Q0YWY4YWJlNzQ4M2YyZWM2ZTMyN2UyM2RkNTY1NGM2MGRhNQ==
5
5
  data.tar.gz: !binary |-
6
- YzRlYWViYjJlYjBlYzk4YzBjY2M1YzAzMTgyOGQ3OGM2ODkwMTEzMg==
6
+ ODM4NjY3M2I4MzdlZjdlZjIxMTkzM2Y0ZGJlMjFhY2UxMWUxMzMyZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDZhMDk5Mjk0OTIxOGNlNDYzMzJmM2JiNzRmNDY3ZTU1OTE1NGYyNTUwMGMy
10
- NTFmN2RlNTg4ZDllZjMzYmFiZmQyNmI4ZGVmMWNlZDVhNDZjNGYzYjRkZDE3
11
- NTQzYjNjNWFmMzVhNzk3N2RlODJiMjBlOTQ3MmFlNzc4NTU1ZGE=
9
+ ZGNlZTQzNzJiN2RjMDliOWE3YjBkNDMzOTVmM2FkYjA4MjY4OWM0ZDgzZjZh
10
+ ZDhiYTRjYWZhZmEyNzMyMmJmNWNmNWNhNGY5OTk5YzhiMDYzZjAwY2U2ZmE0
11
+ ZjY0NTc3ZDQ3YTlkN2U1NWI1NzQ3YTcwN2JjODBiNmQ0NzUwZWM=
12
12
  data.tar.gz: !binary |-
13
- M2U3MzU2M2FhYzllMjUzYThmMzYxNjM0NjU5YjJlM2JhMzEzOGVkYjkxMWMy
14
- N2I3ZDRkNzJkYjZlMDgwNTlhZTczOGVjY2ZiYzMxZGExNzE1Y2NkMjk1NDhi
15
- MmQwZjliYTNiNGY2ZTNiZTY2ODM1NDUxYjJiOWFiZTNhZDNjY2Q=
13
+ ODBhZDg0NmRlN2M1NjhhZTdlY2JmYjI0NTJmZjk0MjVmZDE0ZWIxYmQ2ZjE4
14
+ MjliN2M4ZTgxMjg2M2NlNTlkYjExZDcxYmZhYzA0OTlmODY1MWQ2ODE4MDlk
15
+ YmUwYTM1YjI5ZDBiMTI3MjUxMTYzYTY1Y2E1MTQwMmE2OGM3Y2M=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tgios (0.0.37)
4
+ tgios (0.0.39)
5
5
  awesome_print_motion
6
6
  motion-layout
7
7
  plastic_cup (>= 0.1.1)
@@ -12,17 +12,26 @@ module Tgios
12
12
  k = :proximityUUID if k.to_s == 'uuid'
13
13
  instance_variable_set("@#{k}", v)
14
14
  end
15
+ @proximityUUID ||= NSUUID.new
16
+ @major ||= 34702
17
+ @minor ||= 31202
18
+ @accuracy ||= 3.0
19
+ @rssi ||= -85
20
+ @proximity ||= CLProximityFar
15
21
  end
16
22
  end
17
23
 
18
24
  class BeaconManager < BindingBase
19
25
  attr_accessor :range_method, :range_limit, :tolerance, :current_beacon, :background
26
+ attr_reader :current_bluetooth_state
20
27
  ALGORITHMS = [:continue, :timeout]
21
28
 
22
29
  BeaconFoundKey = 'Tgios::BeaconManager::BeaconFound'
23
30
  BeaconsFoundKey = 'Tgios::BeaconManager::BeaconsFound'
31
+ RangingFailedKey = 'Tgios::BeaconManager::RangingFailed'
24
32
  EnterRegionKey = 'Tgios::BeaconManager::EnterRegion'
25
33
  ExitRegionKey = 'Tgios::BeaconManager::ExitRegion'
34
+ BluetoothChangedKey = 'Tgios::BeaconManager::BluetoothChanged'
26
35
 
27
36
  def self.default=(val)
28
37
  @default = val
@@ -49,23 +58,40 @@ module Tgios
49
58
  self.algorithm = (options[:algorithm] || :continue)
50
59
  @tolerance = (options[:tolerance] || 5)
51
60
 
52
- @uuid = NSUUID.alloc.initWithUUIDString(options[:uuid])
53
- @major = options[:major]
54
- @minor = options[:minor]
55
61
  @range_method = (options[:range_method] || :rssi)
56
62
  @range_limit = (options[:range_limit] || -70)
57
63
 
58
- @region = if @major && @minor
59
- CLBeaconRegion.alloc.initWithProximityUUID(@uuid, major: @major, minor: @minor, identifier: identifier)
60
- elsif @major
61
- CLBeaconRegion.alloc.initWithProximityUUID(@uuid, major: @major, identifier: identifier)
62
- else
63
- CLBeaconRegion.alloc.initWithProximityUUID(@uuid, identifier: identifier)
64
- end
65
- @region.notifyOnEntry = true
66
- @region.notifyOnExit = true
67
- @region.notifyEntryStateOnDisplay = true
64
+ @regions = []
65
+ region_options = options[:regions]
66
+ if !region_options.is_a?(Array)
67
+ region_options = [{uuid: options[:uuid], major: options[:major], minor: options[:minor]}]
68
+ end
69
+
70
+ region_options.each do |region_hash|
71
+ if region_hash.is_a?(Hash)
72
+ uuid = region_hash[:uuid]
73
+ major = region_hash[:major]
74
+ minor = region_hash[:minor]
75
+ else
76
+ uuid = region_hash
77
+ end
78
+ uuid = uuid.upcase
79
+ nsuuid = NSUUID.alloc.initWithUUIDString(uuid)
80
+ region = if major && minor
81
+ CLBeaconRegion.alloc.initWithProximityUUID(nsuuid, major: major, minor: minor, identifier: identifier(uuid, major, minor))
82
+ elsif major
83
+ CLBeaconRegion.alloc.initWithProximityUUID(nsuuid, major: major, identifier: identifier(uuid, major, minor))
84
+ else
85
+ CLBeaconRegion.alloc.initWithProximityUUID(nsuuid, identifier: identifier(uuid, major, minor))
86
+ end
87
+ @regions << {region: region, active: false}
88
+
89
+ region.notifyOnEntry = true
90
+ region.notifyOnExit = true
91
+ region.notifyEntryStateOnDisplay = true
92
+ end
68
93
 
94
+ central_manager
69
95
  start_monitor
70
96
 
71
97
  UIApplicationWillEnterForegroundNotification.add_observer(self, 'on_enter_foreground:')
@@ -73,8 +99,8 @@ module Tgios
73
99
 
74
100
  end
75
101
 
76
- def identifier
77
- [@uuid.UUIDString, @major, @minor].join('/')
102
+ def identifier(uuid, major, minor)
103
+ [uuid, major, minor].join('/')
78
104
  end
79
105
 
80
106
  def on(event_key,&block)
@@ -104,16 +130,18 @@ module Tgios
104
130
  end
105
131
 
106
132
  def locationManager(manager, didEnterRegion: region)
107
- NSLog 'didEnterRegion'
108
133
  did_enter_region(region)
109
134
  end
110
135
 
111
136
  def locationManager(manager, didExitRegion: region)
112
- NSLog 'didExitRegion'
113
137
  did_exit_region(region)
114
138
  end
115
139
 
116
140
  def locationManager(manager, didRangeBeacons: beacons, inRegion: region)
141
+
142
+ region_hash = get_region_hash(region)
143
+ return unless region_hash[:active]
144
+
117
145
  beacons = beacons.sort_by{|b| b.try(@range_method)}
118
146
  beacons = beacons.reverse if @range_method == :rssi
119
147
  known_beacons = beacons.select{|b| b.proximity != CLProximityUnknown}
@@ -124,7 +152,7 @@ module Tgios
124
152
 
125
153
  NSLog("beacons_in_range: ")
126
154
  beacons_in_range.each_with_index do |bir, i|
127
- NSLog("##{i}: major: #{bir.major}, minor: #{bir.minor}, accuracy: #{bir.accuracy}, rssi: #{bir.rssi}")
155
+ NSLog("##{i}: major: #{bir.major}, minor: #{bir.minor}, accuracy: #{bir.accuracy.round(3)}, rssi: #{bir.rssi}")
128
156
  end
129
157
  push_beacon(beacon) # nil value will signify null beacon
130
158
 
@@ -142,7 +170,8 @@ module Tgios
142
170
  end
143
171
 
144
172
  def locationManager(manager, rangingBeaconsDidFailForRegion: region, withError: error)
145
- @events[:ranging_failed].call(region, error) if @events[:range_failed]
173
+ @events[:ranging_failed].call(region, error) if has_event(:ranging_failed)
174
+ RangingFailedKey.post_notification(self, {region: region, error: error})
146
175
  end
147
176
 
148
177
  def location_manager
@@ -178,27 +207,36 @@ module Tgios
178
207
  end
179
208
 
180
209
  def start_monitor
181
- location_manager.startMonitoringForRegion(@region)
182
- location_manager.requestStateForRegion(@region)
210
+ @regions.each do |region_hash|
211
+ region = region_hash[:region]
212
+ location_manager.startMonitoringForRegion(region)
213
+ location_manager.requestStateForRegion(region)
214
+ end
183
215
  end
184
216
 
185
217
  def stop_monitor
186
- location_manager.stopRangingBeaconsInRegion(@region)
187
- location_manager.stopMonitoringForRegion(@region)
218
+ @regions.each do |region_hash|
219
+ region = region_hash[:region]
220
+ location_manager.stopRangingBeaconsInRegion(region)
221
+ location_manager.stopMonitoringForRegion(region)
222
+ end
188
223
  end
189
224
 
190
225
  def on_enter_foreground(noti)
191
- NSLog 'on_enter_foreground'
192
226
  self.performSelector('start_monitor', withObject: nil, afterDelay:1)
193
227
  end
194
228
 
195
229
  def on_enter_background(noti)
196
- NSLog 'on_enter_background'
197
230
  stop_monitor unless @background
198
231
  end
199
232
 
200
233
  def did_enter_region(region)
201
234
  if region.isKindOfClass(CLBeaconRegion)
235
+
236
+ region_hash = get_region_hash(region)
237
+ return if region_hash.blank?
238
+ region_hash[:active] = true
239
+
202
240
  location_manager.startRangingBeaconsInRegion(region)
203
241
  if has_event(:enter_region)
204
242
  @events[:enter_region].call(region)
@@ -209,7 +247,19 @@ module Tgios
209
247
 
210
248
  def did_exit_region(region)
211
249
  if region.isKindOfClass(CLBeaconRegion)
250
+
251
+ region_hash = get_region_hash(region)
252
+ return if region_hash.blank?
253
+ region_hash[:active] = false
254
+
212
255
  location_manager.stopRangingBeaconsInRegion(region)
256
+ @previous_beacons.delete_if {|b|
257
+ beacon = b.is_a?(Hash) ? b[:beacon] : b
258
+ self.class.beacon_in_region(beacon, region)
259
+ }
260
+ if self.class.beacon_in_region(@current_beacon, region)
261
+ @current_beacon = nil
262
+ end
213
263
  if has_event(:exit_region)
214
264
  @events[:exit_region].call(region)
215
265
  end
@@ -217,6 +267,33 @@ module Tgios
217
267
  end
218
268
  end
219
269
 
270
+ def central_manager
271
+ @central_manager ||= CBCentralManager.alloc.initWithDelegate(self, queue: nil)
272
+ end
273
+
274
+ def centralManagerDidUpdateState(central)
275
+ state = central.state
276
+ @current_bluetooth_state = state
277
+
278
+ if has_event(:bluetooth_changed)
279
+ @events[:bluetooth_changed].call(state)
280
+ end
281
+ BluetoothChangedKey.post_notification(self, {state: state})
282
+
283
+ @regions.each do |region_hash|
284
+ region = region_hash[:region]
285
+ case state
286
+ when CBCentralManagerStatePoweredOff, CBCentralManagerStateUnsupported, CBCentralManagerStateUnauthorized
287
+ did_exit_region(region)
288
+ when CBCentralManagerStatePoweredOn
289
+ did_enter_region(region)
290
+ when CBCentralManagerStateResetting
291
+ when CBCentralManagerStateUnknown
292
+ else
293
+ end
294
+ end
295
+ end
296
+
220
297
  def has_event(event)
221
298
  @events.has_key?(event)
222
299
  end
@@ -257,6 +334,8 @@ module Tgios
257
334
  max_beacon_key = count_hash.max_by(&:last).first
258
335
  @current_beacon = @beacons_last_seen_at[max_beacon_key][:beacon]
259
336
  end
337
+ else
338
+ @current_beacon = beacon
260
339
  end
261
340
  end
262
341
 
@@ -266,17 +345,48 @@ module Tgios
266
345
 
267
346
  def self.beacon_eqs(beacon1, beacon2)
268
347
  return beacon1 == beacon2 if beacon1.nil? || beacon2.nil?
269
- beacon1.minor == beacon2.minor && beacon1.major == beacon2.major && beacon1.proximityUUID == beacon2.proximityUUID
348
+ beacon1.minor == beacon2.minor && beacon1.major == beacon2.major && beacon1.proximityUUID.UUIDString.upcase == beacon2.proximityUUID.UUIDString.upcase
349
+ end
350
+
351
+ def self.region_eqs(region1, region2)
352
+ return region1 == region2 if region1.nil? || region2.nil?
353
+ region1.identifier.upcase == region2.identifier.upcase
354
+ end
355
+
356
+ def self.beacon_in_region(beacon, region)
357
+ return false unless beacon
358
+
359
+ match = beacon.proximityUUID == region.proximityUUID
360
+ return false unless match
361
+ major = region.major
362
+ if major
363
+ match = match && beacon.major == major
364
+ return false unless match
365
+ minor = region.minor
366
+ if minor
367
+ match = match && beacon.minor == minor
368
+ end
369
+ end
370
+ match
270
371
  end
271
372
 
272
373
  def self.beacon_key(beacon)
273
- [beacon.try(:proximityUUIDbeacon), beacon.try(:major), beacon.try(:minor)].join('/')
374
+ [beacon.try(:proximityUUID).try(:UUIDString).try(:upcase), beacon.try(:major), beacon.try(:minor)].join('/')
274
375
  end
275
376
 
276
377
  def new_fake_beacon(options)
277
- FakeBeacon.new({uuid: @uuid}.merge(options))
378
+ region_hash = @regions.first
379
+ region = region_hash[:region] if region_hash
380
+ region_options = region ? {uuid: region.proximityUUID, major: region.major, minor: region.minor} : {}
381
+ FakeBeacon.new(region_options.merge(options))
382
+ end
383
+
384
+ def get_region_hash(region)
385
+ region_hash = @regions.find{|r| self.class.region_eqs(r[:region], region) }
386
+ region_hash || {}
278
387
  end
279
388
 
389
+
280
390
  def self.supported
281
391
  CLLocationManager.isRangingAvailable
282
392
  end
@@ -289,6 +399,7 @@ module Tgios
289
399
  @events = nil
290
400
  @current_beacon = nil
291
401
  @previous_beacons = nil
402
+ @regions = []
292
403
  end
293
404
 
294
405
  def dealloc
@@ -282,7 +282,7 @@ module Tgios
282
282
  stop_listen
283
283
  @model=nil
284
284
  @decimal_button=nil
285
- if !@ui_field.nil? && @ui_field.delegate == self
285
+ if !@ui_field.nil? && @ui_field.weakref_alive? && @ui_field.delegate == self
286
286
  @ui_field.delegate = nil
287
287
  toolbar = @ui_field.inputAccessoryView
288
288
  toolbar.items = nil unless toolbar.nil?
data/lib/tgios/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tgios
2
- VERSION = '0.0.38'
2
+ VERSION = '0.0.39'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tgios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.38
4
+ version: 0.0.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - April Tsang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-29 00:00:00.000000000 Z
12
+ date: 2016-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sugarcube