Estimote / iOS-Fleet-Management-SDK

Estimote Fleet Management SDK for iOS
https://developer.estimote.com
MIT License
1.18k stars 398 forks source link

App crashing on startMonitoring #287

Closed tariq235 closed 5 years ago

tariq235 commented 5 years ago

Basic information

Estimote iOS SDK version: 4.27.0 iOS device(s) affected: All devices iOS version(s) affected: All

Description

We are using EstimoteSDK from last 2 years. We use ESTMotionRule and ESTOrientationRule to register the monitoring but all of sudden since yesterday all our apps started crashing on startMonitoring function.

Expected behavior: App should work properly like before and trigger ESTTriggerManagerDelegate whenever there is a state change

Actual behavior: App crashing on startMonitoring function.

What is the new sdk or api to use ESTMotionRule and ESTOrientationRule to monitor the state change ?

heypiotr commented 5 years ago

(A note for the future: when reporting crashes, it's a good idea to attach a crash log/stack trace.)

What is the new sdk or api to use ESTMotionRule and ESTOrientationRule to monitor the state change ?

Sadly, there's no direct replacement. The best I can suggest is to switch to our Bluetooth scanning library:

https://github.com/Estimote/iOS-Bluetooth-Scanning

… and use the EBSUniversalScanner to scan for EBSScanInfoNearable objects:

let scanner = EBSUniversalScanner()
scanner.delegate = self
scanner.startScanForDevicesRepresented(byClasses: [EBSScanInfoNearable.self])

// ...

func universalScanner(_ universalScanner: EBSUniversalScannerProtocol,
                      didScanEstimoteDevice scanInfo: EBSScanInfo) {
    if let scanInfo = scanInfo as? EBSScanInfoNearable {
        print("nearable detected")
        print("ID = \(scanInfo.nearableIdentifier)")
        print("motion state = \(scanInfo.motionState)")
    }
}

ESTMotionRule should be easy to replicate by looking at the motionState of the scanned packet.

ESTOrientationRule will be a little more tricky: you'll need to look at the xAcceleration, yAcceleration, zAcceleration, and try to pinpoint where the Earth's gravity vector shows up. Maybe there are some ready-made resources on the Internet about figuring out orientation based on readings from an accelerometer + the gravity.

I'm going to close this bug report, as it's very unlikely that anything in the (now-called) Fleet Management SDK that's not related to configuring beacons will be worked on.

If you need more help transitioning to our Bluetooth scanning library, feel more than welcome to open a topic about it on our forums: https://forums.estimote.com

tariq235 commented 5 years ago

@heypiotr There is no documentation or sample for https://github.com/Estimote/iOS-Bluetooth-Scanning. How am I supposed to do migration ?

Our hundreds of customers and partners got affected due to sudden crash on previous stable sdk. Why you cannot fix the previous sdk crash and give proper migration guide ?

heypiotr commented 5 years ago

Did you change any code or update the SDK, or has it just started crashing "on its own"? Can you post the crash log? (Also see this post: https://forums.estimote.com/t/apple-rejection-cause-of-background-mode/10349?u=heypiotr, startMonitoring will crash if your app doesn't have the appropriate Background Mode enabled, did you change any Background Mode settings in your app recently?)

I'm happy to help with the migration—the code snippet above should be a good starting point, and for any follow-up questions, maybe you can open a topic on our forums, and we can continue there.

tariq235 commented 5 years ago

@heypiotr It started crashing all of sudden on our stable enterprise build from 30th July onwards. There were no changes made in the app and it was fully functional.

I will try my best to provide you all details code level.

`

    apiService.fetchBeaconsForRegionID(User.region) { [weak self] in $0
        .onSuccess { beacons in
            guard let me = self else { return }
            me.beacons = beacons

            for beacon in beacons {
                let motionRule = ESTMotionRule.motionStateEquals(true, forNearableIdentifier: beacon.beaconID!)
                let movedTrigger = ESTTrigger(rules: [motionRule], identifier: "\(beacon.beaconID!)-moved")
                me.triggerManager.startMonitoring(for: movedTrigger)

                let orientationRule = ESTOrientationRule.orientationEquals(.horizontal, forNearableIdentifier: beacon.beaconID!)
                let restingTrigger = ESTTrigger(rules: [orientationRule], identifier: "\(beacon.beaconID!)-resting")
                me.triggerManager.startMonitoring(for: restingTrigger)
            }
        }
    }
`

`

func triggerManager(_ manager: ESTTriggerManager, triggerChangedState trigger: ESTTrigger) {
    if trigger.state {
        let type = trigger.identifier.components(separatedBy: "-")
        let beaconID = type[0]
        let beaconPosition = type[1]

        if beaconPosition == "resting" {
            // Further logic when resting is called

        } else if beaconPosition == "moved" {
            // Further logic when when moved is called
        }
    }
}

`

Screen Shot 2019-08-20 at 11 01 13 AM

Estimote developer website has complete post about triggers and orientation https://developer.estimote.com/nearables/build-a-nearables-app/

If this is deprecated from new SDK then why website is pointing to old sdk code ? Can you guys update the developer website with new code ? Almost all the code is pointing to old sdk and there is 0 migration guide available. Even fleetsdk samples pointing to the old sdk code.

heypiotr commented 4 years ago

Hey, sorry for late response, I somehow missed your reply. It looks to me from the crash log that you're passing a malformed nearable identifier to our SDK, and our SDK isn't sufficiently resilient to handle that gracefully.

I see that you fetch the list of beacons from your API, so maybe somebody added a new nearable to your system with a malformed identifier, and that's why your app suddenly started crashing.

A simple validation on your backend (nearable identifier = 16 hexadecimal (0-9, a-z) characters) could help prevent this in the future.