user4826471
user4826471

Reputation: 51

How do I send MQTT feed data when app enters background?

I am working on an app which is a MQTT Client to io.Adafruit Broker. I subscribe to various of my feeds including an image feed. I can also Publish to the image feed from another Client camera by touching a button in my app.
My problem is that sometimes when I start Publishing to the image feed I don't stop the Publishing before I put my app in the background. It is then continuously Publishing an image in the background until I open the app back up and manually stop the image Publishing. I would like to have the image Publish to stop when the app enters the background but i can't seem to be able to accomplish this. I have tried the following code in the app delegate.m. I initialize and start the communication in the main view controller and everything works fine.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    NSLog(@"Entering background");
   
    NSString *movie = @"8";
    NSData* data = [movie  dataUsingEncoding:NSUTF8StringEncoding];
    [session3 publishData:data onTopic:self.avideo retain:NO qos:1 publishHandler:nil];
    NSLog(@"movie:%@", movie);
   
    [UIApplication sharedApplication].idleTimerDisabled = NO;
   
}

I get a printout that I enter background and the value of "movie" but It does not publish the value to io.adafruit so the camera continues to Publish images to the image feed. How can I do this?

Upvotes: 0

Views: 29

Answers (0)

Related Questions