googlesamples / ios-nearby

69 stars 30 forks source link

iphone 5, ios 10.3 CoreBluetooth fails: API MISUSE #26

Open ezrover opened 7 years ago

ezrover commented 7 years ago

`messageMgr = GNSMessageManager(apiKey: "ccc", paramsBlock: {(params: GNSMessageManagerParams!) -> Void in }) GNSMessageManager.setDebugLoggingEnabled(true) GNSPermission.setGranted(true) nearbyPermission = GNSPermission(changedHandler: { [unowned self] (granted: Bool) in if granted { guard let mgr = self.messageMgr else { return } self.subscription = mgr.subscription(messageFoundHandler: { (message: GNSMessage?) in print ("Received: (String(describing: message))}") if UIApplication.shared.applicationState != .active { let notification = UNMutableNotificationContent() notification.title = "Received: (String(describing: message))" notification.subtitle = "iD" notification.body = "Welcome"

                    let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
                    _ = UNNotificationRequest(identifier: "notification1", content: notification, trigger: notificationTrigger)
                }
                // Process the new message...
            },messageLostHandler: { (message: GNSMessage?) in
                // Remove the name from the list
                print ("Lost: \(String(describing: message))}")
            },paramsBlock:{ (params: GNSSubscriptionParams?) in
                guard let params = params else { return }
                params.deviceTypesToDiscover = GNSDeviceTypes.bleBeacon | GNSDeviceTypes.usingNearby
                params.messageNamespace = "com.test"
                params.type = "iD"
                params.strategy = GNSStrategy(paramsBlock: { (params: GNSStrategyParams?) in
                    guard let params = params else { return }
                    params.allowInBackground = true
                    params.discoveryMediums = .BLE
                    params.discoveryMode = .scan
                })
            })

            self.beaconTimer.scheduleRepeating(deadline: .now(), interval: .seconds(60))
            self.beaconTimer.setEventHandler { [unowned self] in
                NSLog("Transmitting")

                // Publish the name to nearby devices.
                let name = "com.test"
                let type = "iD"
                let pubMessage: GNSMessage = GNSMessage(content: name.data(using: .utf8, allowLossyConversion: true), type: type)
                self.publication = mgr.publication(with: pubMessage, paramsBlock: { (params: GNSPublicationParams?) in
                                                                    guard let params = params else { return }
                                                                    params.strategy = GNSStrategy(paramsBlock: { (params: GNSStrategyParams?) in
                                                                        guard let params = params else { return }
                                                                        params.allowInBackground = true
                                                                        params.discoveryMediums = .BLE
                                                                        params.discoveryMode = .default
                                                                    })
                })
            }
            self.beaconTimer.resume()
        }else {
            print("DONT HAVE PERMISSIONS!!!")
        }`

Results in CoreBluetooth Error:

Beacon: Start scanning 2017-05-06 22:22:11.200389-0700 s[421:40712] Transmitting 2017-05-06 22:22:11.203035-0700 s[421:40712] Publish (mediums: 2, broadcast/scan: 3, beacons: 0/0/0, background: 0) 2017-05-06 22:22:11.205965-0700 s[421:40652] [CoreBluetooth] API MISUSE: <CBCentralManager: 0x17426e7c0> has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported 2017-05-06 22:22:11.208803-0700 s[421:40712] Beacon: Start scanning 2017-05-06 22:22:11.231810-0700 s[421:40712] [CoreBluetooth] API MISUSE: <CBCentralManager: 0x170466880> has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported

dan-webb commented 7 years ago

This API misuse warning is unavoidable because the Nearby Messages library supports both foreground and background BLE scanning/advertising, and therefore implements the centralManager:willRestoreState: method. Apps that don't enable BLE background mode will unfortunately see this error.