XMPPFramework does not send keep alive in background even with enableBackgroundingOnSocket set to TRUE ! #327

Closed
sepehrom opened this Issue Mar 10, 2014 · 89 comments

Projects

None yet
@sepehrom

I think the title is illustrating enough. I want XMPPFramework to work ( like a service ) in background and receive messages even when app is not in active state. I have set
xmppStream.enableBackgroundingOnSocket = YES;
But no progress here.
The app goes to background, it still receives messages ( and shows notifications ) for a few seconds, but if it be inactive for a few seconds ( and idle also ( no incoming message ) ) it would no longer work in the background.
I have trying logging and saw that the app is sending keep-alive packets, within a few seconds after receiving last message ( last activity ) , but if there be no activity for a few time, it stops sending keep-alives and the app wouldn't be notified and work anymore.
Just in case it matters, I have set "keep alive sending interval" to 5 seconds.

I really appreciate any quick help.
Thanks a lot

@ObjColumnist
Collaborator

Hi,

This only works for VoIP apps, for which you need to specify the voip UIBackgroundMode in your Info.plist.

Even then the experience isn't great because if your app is woken up too many times it will be killed.

@sepehrom

My app is a VOIP app and I have enabled voip UIBackgroundMode in the
info.plist file. Otherwise I couldn't get notifications when the app was in
background !!! The problem is that it seems that it only works for a few
seconds or few minutes in the background, not more than that !!!

On Mon, Mar 10, 2014 at 8:25 PM, Spencer MacDonald <notifications@github.com

wrote:

Hi,

This only works for VoIP apps, for which you need to specify the voip
UIBackgroundMode in your Info.plist.

Even then the experience isn't great because if your app is woken up too
many times it will be killed.

Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-37205502
.

@ObjColumnist
Collaborator

Apps don't get suspended for a few seconds (I think 10 seconds at the most) so non VoIP apps receive messages in the background before they are suspended.

@sepehrom

In my info.plist file :
1 - I have set "Application does not run in background" to NO.
2 - I have added "App provides Voice over IP services" to "Required
background modes"

Am I supposed to do anything else ?

P.s: When I'm in the middle of a VOIP call, I can press the home button and
it won't be interrupted, App continues call while it is not in active state.

On Wed, Mar 12, 2014 at 12:20 PM, Spencer MacDonald <
notifications@github.com> wrote:

Apps don't get suspended for a few seconds (I think 10 seconds at the
most) so non VoIP apps receive messages in the background before they are
suspended.

Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-37386385
.

@ObjColumnist
Collaborator

That should be fine.

The only other thing I can think of is that you set enableBackgroundingOnSocket after you call connect.

@sepehrom

I have called that in my "socketDidConnect" method.
But it will work in background as long as it receive data after entering
background mode. For example if I send it to background and send the app an
XMPP message each for example 5 seconds, it will stay connected forever,
but as soon as I stop sending messages ( or any network traffic ) it stops
sending keep-alive packets too.
I have no idea what would help. Any suggestions ? :-/

On Wed, Mar 12, 2014 at 6:28 PM, Spencer MacDonald <notifications@github.com

wrote:

That should be fine.

The only other thing I can think of is that you set
enableBackgroundingOnSocket after you call connect.

Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-37418115
.

@ObjColumnist
Collaborator

That's how it works unfortunately, VoIP sockets were only added so the server can signal a inbound call to the app:

VoIP Sockets
A VoIP (Voice over IP) app is expected to run continuously so that it can monitor the VoIP control connection; however, to minimize the memory impact on the system, the app is suspended while it's inactive. To make this work the app must register the data socket for its control connection as a VoIP socket. A socket registered in this way has two special features:

While the app is suspended the system monitors the socket on the app's behalf. If any data arrives on the socket, the system resumes execution of the app (albeit in the background), which can then read the data off the socket and take the appropriate action (for example, notifying the user of an incoming call).
The socket's resources are never reclaimed. Thus, the app can safely be suspended without any fear of its socket going deaf.

You can use:

  • (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void (^)(void))keepAliveHandler

In conjunction with:

  • (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler;

To run in the background every 600 secs, but from my experience you will only get a maximum of 60 secs.

@sepehrom

I think I didn't quite got what you meant. There're just 2 minor things:

First of all, according to your words, my app should be resumed and notify
me of for example an incoming XMPP message whenever it comes ( if the
socket hasn't gone deaf ) , but this doesn't happen.
and Second of all, if I'm supposed to register a background task using "
beginBackgroundTaskWithExpirationHandler", then Would you please kindly
take your time and provide a little more details about it ? Like a quick
sample of how should I use it , or where is the appropriate place to call
it ( applicationWillResignActive maybe ? ) , or what should it return ,
etc...

Thank you so much for you kind support

On Wed, Mar 12, 2014 at 11:09 PM, Spencer MacDonald <
notifications@github.com> wrote:

That's how it works unfortunately, VoIP sockets were only added so the
server can signal a inbound call to the app:

VoIP Sockets
A VoIP (Voice over IP) app is expected to run continuously so that it can
monitor the VoIP control connection; however, to minimize the memory impact
on the system, the app is suspended while it's inactive. To make this
work the app must register the data socket for its control connection as a
VoIP socket. A socket registered in this way has two special features:

While the app is suspended the system monitors the socket on the app's
behalf. If any data arrives on the socket, the system resumes execution
of the app (albeit in the background), which can then read the data off the
socket and take the appropriate action (for example, notifying the user of
an incoming call)
.
The socket's resources are never reclaimed. Thus, the app can safely be
suspended without any fear of its socket going deaf.

You can use:

  • (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void
    (^)(void))keepAliveHandler

In conjunction with:

  • (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void
    (^)(void))handler;

To run in the background every 600 secs, but from my experience you will
only get a maximum of 60 secs.

Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-37454236
.

@ObjColumnist
Collaborator

That middle bit is from an Apple Tech Note but my markdown skills on an iPad meant it didn't quote properly 😄 https://developer.apple.com/library/ios/technotes/tn2277/_index.html

In application did enter background or when the keep alive handler is called you can ask for more time using beginBackgroundTaskWithExpirationHandler
https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/beginBackgroundTaskWithExpirationHandler:

@sepehrom
sepehrom commented May 1, 2014

Hi again,

I finally managed to configure that and make the app work in background.

But here's another problem.
The app works perfectly in the background, and I see the log showing that a
keep alive packet is being sent each few seconds. But after exactly 3
minutes ( after going to background ), I get an exception and the app is
terminated because xmpp keep alive's method is being invoked on an
incorrect queue, and the assertion in the first line of method fails.

An screenshot is attached to the message for more elaboration.
I would be thankful and it would be great if you kindly take your time and
provide any solutions.

Best regards

@ObjColumnist
Collaborator

The screenshot didn't get added 😄

@sepehrom
sepehrom commented May 1, 2014

Since I'm attaching on my iPhone , I don't see much information about
attachment, I just see "attached" phrase next to the name of file 😄

Re-attached it to this message :)

On Thursday, May 1, 2014, Spencer MacDonald notifications@github.com
wrote:

The screenshot didn't get added [image: 😄]


Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-41890594
.

@sepehrom
sepehrom commented May 1, 2014

Got the screenshot ? Any ideas ? :)

On Thursday, May 1, 2014, Amir Sepehr itunesmad.05@gmail.com wrote:

Since I'm attaching on my iPhone , I don't see much information about
attachment, I just see "attached" phrase next to the name of file 😄

Re-attached it to this message :)

On Thursday, May 1, 2014, Spencer MacDonald <notifications@github.comjavascript:_e(%7B%7D,'cvml','notifications@github.com');>
wrote:

The screenshot didn't get added [image: 😄]


Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-41890594
.

@ObjColumnist
Collaborator

Nope, looks like you can't add images via email.

@sepehrom
sepehrom commented May 2, 2014

I just checked on my Mac to see if there is any problem with the
screenshot, but I don't see any.
I can see the ones I attached, and I dunno why it is not accessible by your
side :)
Anyways , I uploaded it somewhere else, and here's the link :
http://i.imgur.com/27UBz17.png

Thanks again,
Best Regards

On Thu, May 1, 2014 at 11:14 PM, Spencer MacDonald <notifications@github.com

wrote:

Nope, looks like you can't add images via email.


Reply to this email directly or view it on GitHubhttps://github.com/robbiehanson/XMPPFramework/issues/327#issuecomment-41942420
.

@ObjColumnist
Collaborator

Assuming you don't call keepAlive directly, I am not sure why it would suddenly switch queues and therefore throw an exception.

@mouli1102

Hi,

My app works perfectly in the foreground. When the app goes to background and after 3 minutes i get an exception and the app is terminated because xmpp keep alive.

@ObjColumnist
Collaborator

What is the exception?

@mouli1102

Keep alive method invoked on incorrect queue.

@mouli1102

I am facing the same issue as the user sepehrom. App gets terminated after 3 minutes or more. I have enabled the background socket and also added "App provides Voice over IP services" to "Required
background modes". in plist.

@mouli1102

Hi Spencer,

Could you please look into this issue? We are developing the app with XMPP and we need our app to work in background mode so can you please tell me when the issue will be fixed?

@adozenlines

If this app is an iOS app and it is not a VoIP app and is for the App Store
it might be rejected for using back ground modes.

On Friday, June 13, 2014, mouli1102 notifications@github.com wrote:

Hi Spencer,

Could you please look into this issue? We are developing the app with XMPP
and we need our app to work in background mode so can you please tell me
when the issue will be fixed?


Reply to this email directly or view it on GitHub
#327 (comment)
.

@vaiism
vaiism commented Jun 13, 2014

For an iOS app - you can't just set background mode and expect to work -
you can either register for Location Services and get @10 mins or so, or as
a VOIP app to get full background.

We have a custom server based on vysper (and report locations) so we can
tell when a client has gone offline (after the Location Services timeout
for background apps) - and send APNS messages to those clients that are in
that mode.

If you have VOIP built into your app, you can do so - but you can't just
claim it and not truly support it, or the app store will kick back.

On Fri, Jun 13, 2014 at 10:10 AM, mouli1102 notifications@github.com
wrote:

Hi Spencer,

Could you please look into this issue? We are developing the app with XMPP
and we need our app to work in background mode so can you please tell me
when the issue will be fixed?


Reply to this email directly or view it on GitHub
#327 (comment)
.

@sepehrom

Hi Guys,

I've been dealing with this in my app for like more than a month.
My app was an actual VOIP & Messaging app, and I used XMPPFramework to handle messaging part.
I was facing this problem until I got the above reply from "ObjColumnist" user, mentioning how to enable backgrounding. I already set enableBackgroundingOnSocket enabled, I already set VOIP Backgrounding Mode enabled, I had done almost everything but it was not working.

After those suggestions I used "beginBackgroundTaskWithExpirationHandler" in my "applicationDidEnterBackground" method and Inside that expiration handler, I manually sent a keep alive packet. I did that because it was being expired and I wanted to have some activity on the network so that it can buy me a little bit more time.
That made situation a little better, but after a few minutes I was getting that KEEP ALIVE ON WRONG QUEUE exception. I did some tracing and I deleted that line in expiration handler, because as far as I could understand ( I'm not an expert in networking on mobile platforms ) you should NEVER EVER send a keep alive packet manually ( I.E: you should never send [xmppStream keepAlive] message).
I deleted everything and it kinda fixed everything.

I know, it sounds like Adding something and then Deleting it, so that nothing's done at all, But weirdly, it is fixed now, and I'm not getting that exception anymore. AlThough I don't feel like XMPPFramework be in a stable situation when my app goes to background ( I don't feel safe ), but I think the reason is in the way I have set it up.

Hope this can help you in that backgrounding option. I don't have access to the app's source code, but I can post every part of code that contains something I did to fix that in my app in a few days.
It would be great to hear your comments.
Thanks

@mouli1102

Hi sepehrom,
Our application already runs in background mode with TCP connection and also supports VOIP. But now i want to use chat kind of application so i preferred to use XMPP. I have already enabled enableBackgroundingOnSocket and in plist we added "App provides Voice over IP services" to "Required background modes". Application works well in foreground mode, but if it goes to background mode it has been terminated after 3 or more minutes. I have used "beginBackgroundTaskWithExpirationHandler" in my "applicationDidEnterBackground" method but i am getting the exception as "Keep alive on Wrong queue". Can you please tell me the workaround you have made for this?

Thanks

@sepehrom

Hi,

I just did the same steps you mentioned. Can you please tell me what is in
your "expirationHandler" block ? :)

On Monday, June 16, 2014, mouli1102 notifications@github.com wrote:

Hi sepehrom,
Our application already runs in background mode with TCP connection and
also supports VOIP. But now i want to use chat kind of application so i
preferred to use XMPP. I have already enabled enableBackgroundingOnSocket
and in plist we added "App provides Voice over IP services" to "Required
background modes". Application works well in foreground mode, but if it
goes to background mode it has been terminated after 3 or more minutes. I
have used "beginBackgroundTaskWithExpirationHandler" in my
"applicationDidEnterBackground" method but i am getting the exception as
"Keep alive on Wrong queue". Can you please tell me the workaround you have
made for this?

Thanks


Reply to this email directly or view it on GitHub
#327 (comment)
.

@mouli1102

Hi,

In expiration block i added setEnableBackgroundingOnSocket to YES. Also i tested the application after removing all stuffs in expiration handler still the app doesn't run after 3 or more minutes in background mode.

@sepehrom

Hi,

Delete that line so that there be nothing in expiration handler block.
Then inside
"- (void)xmppStream:(XMPPStream *)sender socketDidConnect:(GCDAsyncSocket *)socket"
set
"xmppStream.enableBackgroundingOnSocket = YES;"
and see if this works.

Best Regards,
Amir

@sepehrom

You can also use
"sender.enableBackgroundingOnSocket = YES;"
But the first line worked for me so I didn't try this.
👍

@mouli1102

Hi,

I tried all things but nothing works for me.

@ObjColumnist
Collaborator

You are meant to set enableBackgroundingOnSocket before you connect an XMPPStream, as this value is only checked during the connection process i.e. calling it after the stream has been established will mean that it is ignored.

@mouli1102

Hi,

Before establishing connection I have enabled enableBackgroundingOnSocket to YES. In that case also the app does'nt work in background mode after 3 or more minutes.

@ObjColumnist
Collaborator

It is strange, I have never seen this issue and I have been running the XMPPStream in the background for a few years.

keepAlive is only called internally by the XMPPStream:

keepAliveTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, xmppQueue);

dispatch_source_set_event_handler(keepAliveTimer, ^{ @autoreleasepool {

    [self keepAlive];
}});

So it _should_ be impossible for it to be called on the wrong queue.

@adamk77
adamk77 commented Jun 18, 2014

mouli1102 --

Another possibility is that with the VOIP flag set on the socket, if the app is woken up more than 15 times in 300 seconds, the OS will kill the app.

@mouli1102

Hi,

At present i am not getting the exception but my app is woken up more than 15 times in 300 seconds and its get crashed. Any ideas for preventing this issue?

@ObjColumnist
Collaborator

This happens because the app is woken up everytime it receives and XMPP Stanza. The only solution is to throttle/filter the stanzas that are sent by the server e.g. Send the Stanzas in batches, don't send presence etc

@mouli1102

My application works perfectly in background mode.Thank you guys.

@mouli1102

Whether XMPP framework will work in iOS 8 SDK(Xcode 6 beta)?

@ObjColumnist
Collaborator

Yeah, but there are a few deprecation warnings in GCDAsyncSocket.

Regards

Spencer

On Thursday, 19 June 2014 at 08:02, mouli1102 wrote:

Whether XMPP framework will work in iOS 8 SDK(Xcode 6 beta)?


Reply to this email directly or view it on GitHub (#327 (comment)).

@mouli1102

Hi Spencer,

I need some clarification regarding XMPP in iOS 8 SDK. Whether it is safe to use XMPP framework in iOS 8 SDK? If so then any major functionality gets affected or any chance for app crash due to depricated warnings.

@ObjColumnist
Collaborator

Through my limited tested everything works fine, but you can't submit apps compiled against the iOS 8 SDK until it is released anyway.

@MrBoog
MrBoog commented Nov 19, 2014

Hi ,Guys:

sorry to bother you all...

I am also have the same question.
Did you guys try to use APNS replace VoIP to push message??
Does apple allow the app has been running it ,won't reject?
And if we use VoIP , my app will never terminates?

I ask same question on SO : check this

@ObjColumnist
Collaborator

Your app gets suspended and is woken up whenever data is received, the app doesn't constantly run.

If your app doesn't actually have VoIP functionality, it won't be approved though.

@sepehrom

Hi guys,

I haven't implemented APNs because of some server side problems but I
guess, that is the correct solution to make this work. I currently use
backgrounding on socket, but after a random time socket disposes with an
error saying that "remote peer closed connection" .
I'm really wondering if there is A "working and reliable" solution other
than push notifications to make sure that app remains alive in the
background for like days ...

On Wednesday, November 19, 2014, Spencer MacDonald notifications@github.com
wrote:

You're app gets suspended and is woken up whenever data is received, the
app doesn't constantly run.

If your app doesn't actually have VoIP functionality, it won't be approved
though.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

Can't you just reconnect when this happens?

The connection will never stay open "for ever" as ip address, dhcp leases etc all expire at some point.

@sepehrom

Dear spencer,

When this happens, app is actually not alive in background, or in other
words, the memory allocated by app gets free by the OS ! So I can't run any
commands and you see when an app is relaunched and the last active state's
snapshot appears for a few moments , and then you are redirected to app's
initial view controller, That's what happens next.
I guess it is done by OS, since when that happens, my voice calls are not
received either !

On Wednesday, November 19, 2014, Spencer MacDonald notifications@github.com
wrote:

Can't you just reconnect when this happens?

The connection will never stay open "for ever" as ip address, dhcp leases
etc all expire at some point.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

OK, I am guessing that is because the app gets woken up too many times while in the background.

@sepehrom

Is there any limitations regarding the times that an app can be woken up ?

On Wednesday, November 19, 2014, Spencer MacDonald notifications@github.com
wrote:

OK, I am guessing that is because the app gets woken up too many times
while in the background.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

If your app is woken up more than 15 times in 300 seconds it will be killed by iOS.

@sepehrom

Is this documented anywhere ?
By the way, does that mean your app has to be killed if you receive like 20
consecutive messages ? Thet seems a bit idd, because you can't prevent
others from messaging, right ?
In other hand, I just tested and faced a case in which my app was not woken
up by any messages and calls, but got killed in about an hour.
Should I set anything to tell the OS not to kill my app ? Apparently such
thing doesn't happen to Line or Viber or famous apps !

On Wednesday, November 19, 2014, Spencer MacDonald notifications@github.com
wrote:

If your app is woken up more than 15 times in 300 seconds it will be
killed by iOS.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

The exact amounts aren't documented anywhere, but if it happens it is stated in the crash log.

Viber uses push notifications, so it doesn't run in the background but I'm not sure about Line. Either way if you control the server you can throttle the messages so they are sent in batches, only send the first message for every chat etc

@sepehrom

Thanks a lot for your suggestions :)
So how does Viber prevent OS from getting it killed ? For example, even
after serveral days, without network activity, I switch to viber and it is
still in the exact situation where I had left. Is it some kind of saving
and loading state when app goes to background and foreground ? Or Viber
actually does something to prevent getting killed ?
Thanks a lot

On Wednesday, November 19, 2014, Spencer MacDonald notifications@github.com
wrote:

The exact amounts aren't documented anywhere, but if it happens it is
stated in the crash log.

Viber uses push notifications, so it doesn't run in the background but I'm
not sure about Line. Either way if you control the server you can throttle
the messages so they are sent in batches, only send the first message for
every chat etc


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

Yeah iOS has State Restoration APIs https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIStateRestoring_protocol/index.html but it might be easier to have you own solution e.g. Save the current tab index in NSUserDefaults.

@sepehrom

I wasn't aware of that protocol. Lots of thanks :)

@mouli1102

Hi sephron,

If your app wakes up more than 15 times in 300 secs excluding notifications messages(Push notifications or UILocalnotifications) are considered as wake up.

@sepehrom

Dear Spencer,

I final could extract a log which is generated at the moment in which my
app is being killed. Apparently it is regarding the XMPP keepAlive method.
Here's the log. Do you have any idea what the source exactly is and what
should I do ? ( This time it got killed without any push notifications or
local notifications or incoming message or incoming call )

*: <BKNewProcess: 0x12765f800; myapp.bundle.identifier; pid:
14032> has active assertions beyond permitted time: *

  • {(*

  • <BKProcessAssertion: 0x12754a7f0> id:
    

    14032-6181E757-F8AB-4A49-9A56-FD686E84173D name: Called by MyAppName, from
    -[XMPPStream keepAlive] process: <BKNewProcess: 0x12765f800;
    myapp.bundle.identifier; pid: 14032> permittedBackgroundDuration:
    180.000000 reason: finishTask owner pid:14032 preventSuspend
    preventIdleSleep preventSuspendOnSleep *

  • )}*

Nov 27 16:10:56 Amirs-iPhone assertiond[58] : Forcing crash
report of <BKNewProcess: 0x12765f800; myapp.bundle.identifier; pid:
14032>...

Nov 27 16:10:56 Amirs-iPhone ReportCrash[14044] :
task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4:
(os/kern) invalid argument)

Nov 27 16:10:56 Amirs-iPhone assertiond[58] : Finished crash
reporting.

Nov 27 16:10:56 Amirs-iPhone mediaserverd[19] : ''
myapp.bundle.identifier(pid = 14032) setting DiscoveryMode =
DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None

Nov 27 16:10:56 Amirs-iPhone com.apple.xpc.launchd1 : Service
exited due to signal: Killed: 9

Nov 27 16:10:56 Amirs-iPhone assertiond[58] : pid_suspend failed
for <BKNewProcess: 0x12765f800; myapp.bundle.identifier; pid: 14032>:
Unknown error: -1, Unknown error: -1

Nov 27 16:10:56 Amirs-iPhone assertiond[58] : assertion failed:
12A405: assertiond + 57880 [1C8478C4-DE3E-3E03-B9D7-144E2128E9EC]: 0x3

*Nov 27 16:10:56 Amirs-iPhone Unknown[58] : *

Nov 27 16:10:56 Amirs-iPhone SpringBoard[48] : Application
'UIKitApplication:myapp.bundle.identifier[0xa51]' exited abnormally via
signal.

Nov 27 16:10:56 Amirs-iPhone SpringBoard[48] : Memory level is
not normal or this app was killed by jetsam. Pending auto-relaunch of
'<FBApplicationProcess: 0x155e6edb0; MyAppName; pid: -1>'.

Nov 27 16:10:56 Amirs-iPhone UserEventAgent[13816] :
id=myapp.bundle.identifier pid=14032, state=0

On Thu, Nov 20, 2014 at 12:46 PM, mouli1102 notifications@github.com
wrote:

Hi sephron,

If your app wakes up more than 15 times in 300 secs excluding
notifications messages(Push notifications or UILocalnotifications) are
considered as wake up.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

I can't see how keepAlive would keep the process awake, it is not blocking or setting up any background tasks.

You can disable keep alive by setting keepAliveInterval to 0 so maybe try that?

@sepehrom

If I disable keepAlive packets, then how should I tell the server that I'm
actually alive in the background?

On Friday, November 28, 2014, Spencer MacDonald notifications@github.com
wrote:

I can't see how keepAlive would keep the process awake, it is not blocking
or setting up any background tasks.

You can disable keep alive by setting keepAliveInterval to 0 so maybe try
that?


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

The app is suspended, so these wouldn't be sent anyway while the app is in the background.

@sepehrom

I have modified the keepAlive method, and have lit an NSLog there, so I see
when a keepAlive packet is actually sent.
Prior to this crash and the app being killed, all keepAlive packets are
being sent with the right interval in the background.

On Friday, November 28, 2014, Spencer MacDonald notifications@github.com
wrote:

The app is suspended, so these wouldn't be sent anyway while the app is in
the background.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

I'm guessing something else is keeping the app awake then, as the app should be suspended.

The problem with debugging this, is some of Apple's restrictions don't apply while the device is plugged in, so you can't test it while debugging from Xcode.

@sepehrom

My app is a VOIP and Messaging app, so beside XMPP and Messaging
functionality it also provides VOIP calls and it has the VOIP Background
mode enabled in its info.plist. Can that cause any problem ? Because the
VOIP service is running in order to get calls from other users. !!!

On Fri, Nov 28, 2014 at 1:12 PM, Spencer MacDonald <notifications@github.com

wrote:

I'm guessing something else is keeping the app awake then, as the app
should be suspended.

The problem with debugging this, is some of Apple's restrictions don't
apply while the device is plugged in, so you can't test it while debugging
from Xcode.


Reply to this email directly or view it on GitHub
#327 (comment)
.

@ObjColumnist
Collaborator

No I have used it myself alongside VoIP (using PJSIP).

The app still gets suspended though, the OS just keep the sockets marked as VoIP alive and when the socket receives data it wakes up the app.

@dipang90

hay ObjColumnist ,

i had same issue as it was describe by mouli1102.i didnt set voip mode for my XMPP chat application instade of that i am using following code for backgrounding.
UIBackgroundTaskIdentifier bgTask = 0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];

}];

i also use some of the solutions as describe in discussion like,

  • (void)xmppStream:(XMPPStream *)sender socketDidConnect:(GCDAsyncSocket *)socket
    set
    "xmppStream.enableBackgroundingOnSocket = YES;"

Also,

"sender.enableBackgroundingOnSocket = YES;"

but i am as same state as i was,my connection lost after 3 minute.

so can you please guide me through this problem?

@ObjColumnist
Collaborator

beginBackgroundTaskWithExpirationHandler only gives you a small amount of time to run in the background, normally it is about 30 seconds.

What happens after 3 mins, does the app get killed?

@dipang90

app dosen't kill but connection not be stable i lost connection.

@ObjColumnist
Collaborator

I'm not sure what to suggest then.

@dipang90

no worries thanks for your reply.
i really appreciate.
thanks.

@mouli1102

Better check the server settings. Your app might have lost the connection
after 15 wakes.

On Mon, Jan 19, 2015 at 4:26 PM, dipang90 notifications@github.com wrote:

no worries thanks for your reply.
i really appreciate.
thanks.


Reply to this email directly or view it on GitHub
#327 (comment)
.

Thanks & Regards,
Chandramouli

@dipang90

Can you please explain in brief?
i dont understand what you want to say about server setting.
i am using eJabber 14.12 we set ping interval 30 sec.

@mouli1102

Set the ping interval 90sec and check.

On Mon, Jan 19, 2015 at 4:34 PM, dipang90 notifications@github.com wrote:

Can you please explain in brief?
i dont understand what you want to say about server setting.
i am using eJabber 14.12 we set ping interval 30 sec.


Reply to this email directly or view it on GitHub
#327 (comment)
.

Thanks & Regards,
Chandramouli

@dipang90

ok let me check.

@UB-CR
UB-CR commented Dec 15, 2015

So, finally how did you resolve the background issue?

@JaydeepPatel

@ObjColumnist hello Sir,
I want get notification when app in background mode. i set (App provides Voice over IP services) in .plist file. My application not using VOIP. only use XMPP LocalNotification. But Apple reject the VOIP service.
So, Please Help me and guide me How can i get notification in background mode also ?

Thank x in advance,

@dipang90
dipang90 commented Apr 9, 2016

Just remove from .plist. And set background  fetch mode.  Set push notification and background fetch method to handle notification. 

Sent from Outlook Mobile

On Sat, Apr 9, 2016 at 5:33 AM -0700, "JaydeepPatel" notifications@github.com wrote:

@ObjColumnist hello Sir,

I want get notification when app in background mode. i set (App provides Voice over IP services) in .plist file. My application not using VOIP. only use XMPP LocalNotification. But Apple reject the VOIP service.

So, Please Help me and guide me How can i get notification in background mode also ?

Thank x in advance,


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@JaydeepPatel

@dipang90 so remove localnotification ? and implement pushnotification only ?

@dipang90
dipang90 commented Apr 9, 2016

No . VoIP Remove. Otherwise all ok. Set local n push both. 

Sent from Outlook Mobile

On Sat, Apr 9, 2016 at 5:45 AM -0700, "JaydeepPatel" notifications@github.com wrote:

@dipang90 so remove localnotification ? and implement pushnotification only ?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@JaydeepPatel

@dipang90 ok sir, But Push Notification set Only in Backgroud method right ?

@dipang90
dipang90 commented Apr 9, 2016

Ya. U search about background fetch. 

Sent from Outlook Mobile

On Sat, Apr 9, 2016 at 5:49 AM -0700, "JaydeepPatel" notifications@github.com wrote:

@dipang90 ok sir, But Push Notification set Only in Backgroud method right ?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@JaydeepPatel

@dipang90 hello sir, I am working on Chat Application. and I want to try get all message in background mode using XMPP. But as you have suggested to use Pushnotification with background fetch mode, do i need to send all the messages using pushnotification ? and also if there is huge chatting users then how we can handle messages using push notification any idea?

@dipang90

Set ping interval or something that server knows the user is offline. Then any user can send message then server check about user status if online or offline. Then server send the push notifications with payload of 256 byte. Offline user access payload and show the message to list.    In payload their is dictionary which have id, message and any filter based on your requirements. 
Try it. If anything has problems mail me. 

Sent from Outlook Mobile

On Mon, Apr 11, 2016 at 8:00 AM -0700, "JaydeepPatel" notifications@github.com wrote:

@dipang90 hello sir, I am working on Chat Application. and I want to try get all message in background mode using XMPP. But as you have suggested to use Pushnotification with background fetch mode, do i need to send all the messages using pushnotification ? and also if there is huge chatting users then how we can handle messages using push notification any idea?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@JaydeepPatel

@dipang90 when app terminated than User is disconnect from the XMPP server.
But I want Continue User Connection. is that possible ? also set this xmppStream.enableBackgroundingOnSocket = YES; from my side.. but i want continue connected..

@dipang90

About termination user disconnected from server.

Sent from Outlook Mobile

On Sat, Apr 16, 2016 at 5:15 AM -0700, "JaydeepPatel" notifications@github.com wrote:

@dipang90 when app terminated than User is disconnect from the XMPP server.

But I want Continue User Connection. is that possible ? also set this xmppStream.enableBackgroundingOnSocket = YES; from my side.. but i want continue connected..


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@JaydeepPatel
JaydeepPatel commented Apr 16, 2016 edited

@dipang90 yes.. But i want Set Continue Connection that is possible when app is terminate .. is that possible ?

@dipang90

No. Never

Sent from Outlook Mobile

On Sat, Apr 16, 2016 at 5:20 AM -0700, "JaydeepPatel" notifications@github.com wrote:

@dipang90 yes.. But i want Set Continue Connection that is possible when app is terminate ..


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@JaydeepPatel
JaydeepPatel commented Apr 16, 2016 edited

@dipang90
ok sir,,,,thank you ..:-) same as like this is my Question..
http://stackoverflow.com/questions/36625624/xmpp-app-terminate-and-not-recive-message

Please noone give answer so please help me....

@JaydeepPatel

@dipang90 no any other way for user stay Continue Connected in XMPP server ?

@JaydeepPatel

@ObjColumnist sir, Can i continue connect and get online user in XMPP when app is Terminated ?

@chrisballinger
Collaborator
@chrisballinger chrisballinger locked and limited conversation to collaborators Apr 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.