0

My App is a Tracking App, I use to implement the tracking functionality PubNub like this tutorial : PubNub Tracking

But my problem is, when the user kill the app, the PubNub stop sending messages.

So my question: is there anyway to still sending messages via PubNub even if the app is killed?

Thanks.

Rawan
  • 1,589
  • 4
  • 23
  • 47
  • If your app is killed then it is dead, so it can't do anything – Paulw11 Jun 05 '16 at 11:20
  • 1
    @Paulw11 but when the app is killed I can to still track the location via coreLocation so that's why I thought that pubNub can be called even if the app killed. – Rawan Jun 05 '16 at 11:54
  • Then the app isn't killed. If you are still getting calls to your location delegate then you can still publish messages. Perhaps you could show some code and explain what you are seeing and what you expect – Paulw11 Jun 05 '16 at 12:02

2 Answers2

2

PubNub Running in Background on iOS

@Rawan is right - you can connect to PubNub when you app is active in the foreground and also when your app is running in the background (which means you have permission from Apple and the device owner/user to do so).

But if the app is killed (not running at all) then that app has no connection to anything, including PubNub.

Ray Wenderlich has a great iOS background modes tutorial.

Community
  • 1
  • 1
Craig Conover
  • 4,710
  • 34
  • 59
  • You can also use PubNub in an App Exension. [Here is a demo](https://github.com/pubnub/extensions) – gurooj Jun 08 '17 at 19:18
0

You can do this by using pubnub Push notification

  1. Enable the push notification on pubnub admin console and Set your certificates
  2. client side : enable push notification on the required channel

Adding Device to Channel

PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                              subscribeKey:@"demo"];
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"]
                     withDevicePushToken:self.devicePushToken
                           andCompletion:^(PNAcknowledgmentStatus *status) {

 // Check whether request successfully completed or not.
 if (!status.isError) {

    // Handle successful push notification enabling on passed channels.
 }
 // Request processing failed.
 else {

    // Handle modification error. Check 'category' property to find out possible issue because
    // of which request did fail.
    //
    // Request can be resent using: [status retry];
 } }];
  1. Change your publish method publish to APNS devices with the PubNub

4 . Important message formet

{    "pn_apns": {  "aps" : {

        "alert": "Game update 49ers touchdown",


 "badge": 2
 }, 
 "teams" : ["49ers", "raiders"],
 "score" : [7, 0]
 }, 
 "your_message" : {
 "date" : "2014.05.20",
 "foobar" : "Data that is not pertinent to devices" 
 }
 }

For background message (iOS Mobile Push Gateway Tutorial)

Vishal Gaur
  • 658
  • 6
  • 18