novastone-media / MQTT-Client-Framework

iOS, macOS, tvOS native ObjectiveC MQTT Client Framework
Other
1.84k stars 466 forks source link

Setting PERSISTENCE = YES #444

Closed sjhennion closed 6 years ago

sjhennion commented 6 years ago

I'm not sure if this is an issue, or if I'm misunderstanding something. When I create a session, as the MQTTSession header suggests, I immediately set the persistence flag to true with an MQTTCoreDataPersistence object. However, since there's no initializer for the MQTTCoreDataPersistence type that takes a persistence value, by the time createPersistentStoreCoordinator: is called, persistence is still set to the default of NO, so the persistent store isn't created with my YES (true).

What this means for me is that if I start my app either with airplane mode on, or disabling it soon after launch, attempt to publish some data, and then kill the app before ever restoring the connection, the data is not available and attempting to publish on the next instance. However, I tried setting the default value for persistence to yes rather than no, and everything worked as expected.

For what it's worth, here's my session initialization:

    func prepManager(userName: String, password: String, deviceId: String) {
        guard let _session = MQTTSession() else {
            print("Error getting MQTT sesh")
            return
        }

        let persistence = MQTTCoreDataPersistence()
        persistence.persistent = true
        _session.persistence = persistence

        /* Other session settings */

        self.session = _session
    }
jcavar commented 6 years ago

Thanks for reporting!

There is now 0.14.0 release, please try it out.