Hello,
I am using PJSIP 1.12.. I did not run any special config when I compiled the libraries.. just compile for ARM6 and ARM7 then merge.. I am trying to get background working so:
I used TCP instead of UDP as my protocol.
I checked PJ_ACTIVESOCK_TCP_IPHONE_OS_BG and PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT in OS_autu.h and I see both of the defined as 1. I see both of them defined in a “#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0” so I did not change anything...
I added Required Background mode flag into my test App plist file
When I launch my app from xcode by hitting the run button, then I press home on the device to put the app in background mode I see logs from my registration function every 60 seconds as expected. and when I call the device I hit the on_incomming_call event as expected....
But when I launch the app from the device itself just click on its icon the background does not work..
if I tried to call the device after 60 seconds, Astersik will say the device is not registered which mean the background socket did not respond to the Keep alive message between the server and the device..if I removed the plist entry about background mode It does not work in both cases (launch from xcode and launch from device), so I think I am on the right path...
To confirm that my settings are good i added log success to “static void activesock_create_iphone_os_stream(pj_activesock_t *asock)” when it set kCFStreamNetworkServiceTypeVoIP and I see that log when I start the app from xcode but again I know it is working from xcode but not as a stand alone..
Am I missing something else?? I have been researching this issue an I am not sure what is missing? Anyone who did get background mode to work ??
Thanks,,,,,
I think we were talking on stack overload :)
The iOS background wakeup should happen once every 10 minutes (600 seconds), and no sooner. If you're seeing it sooner, then your app is probably not suspended. You should put in a regular log (every 10s or something like that) so you can tell for sure when it's active or suspended (because the log entries will stop until you're woken up). Also put a log entry in the wake-from-suspend callback. Most likely the problem is in this area.
The not-registered message usually comes from using the NDLB flag. If you watch the registrations in the sip server logs, you'll see the timeout in the server's response, right after the acknowledgement (set sofia loglevel all 9 if you aren't seeing it, and start with TPORT_LOG=1 ./freeswitch). It's usually 30 seconds when using NDLB. After that, the server will reject call attempts with the not registered message.
--
Michael Fortson
On Wednesday, February 8, 2012 at 7:28 AM, Ashraf Jaddo wrote:
Hello,
I am using PJSIP 1.12.. I did not run any special config when I compiled the libraries.. just compile for ARM6 and ARM7 then merge.. I am trying to get background working so:
I used TCP instead of UDP as my protocol.
I checked PJ_ACTIVESOCK_TCP_IPHONE_OS_BG and PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT in OS_autu.h and I see both of the defined as 1. I see both of them defined in a “#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0” so I did not change anything...
I added Required Background mode flag into my test App plist file
When I launch my app from xcode by hitting the run button, then I press home on the device to put the app in background mode I see logs from my registration function every 60 seconds as expected. and when I call the device I hit the on_incomming_call event as expected....
But when I launch the app from the device itself just click on its icon the background does not work..
if I tried to call the device after 60 seconds, Astersik will say the device is not registered which mean the background socket did not respond to the Keep alive message between the server and the device..if I removed the plist entry about background mode It does not work in both cases (launch from xcode and launch from device), so I think I am on the right path...
To confirm that my settings are good i added log success to “static void activesock_create_iphone_os_stream(pj_activesock_t *asock)” when it set kCFStreamNetworkServiceTypeVoIP and I see that log when I start the app from xcode but again I know it is working from xcode but not as a stand alone..
Am I missing something else?? I have been researching this issue an I am not sure what is missing? Anyone who did get background mode to work ??
Thanks,,,,,
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org (mailto:pjsip@lists.pjsip.org)
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Sorry, missed that you were using Asterisk now. But the first issue to
address is getting multitasking working on its own, and verifying that
the app is waking up every 10 minutes to re-register.
One more quick note about Xcode and app suspend: you need to lock the
screen after hitting the home button, in order to fully suspend the
app.
In the application delegate, here's how the sample app registers the
10 minute callback:
#define KEEP_ALIVE_INTERVAL 600
(void)applicationDidEnterBackground:(UIApplication *)application
{
[app performSelectorOnMainThread:@selector(keepAlive)
withObject:nil waitUntilDone:YES];
[application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{
[app performSelectorOnMainThread:@selector(keepAlive)
withObject:nil waitUntilDone:YES];
}];
}
(void)keepAlive {
NSlog(@"WAKE from sleep called");
if (!pj_thread_is_registered())
{
pj_thread_register("ipjsua", a_thread_desc, &a_thread);
}
pjsua_acc_set_registration(0, PJ_TRUE); //actually sends the
registration update
}
So the main tasks, in order, are:
And then:
On Wed, Feb 8, 2012 at 7:28 AM, Ashraf Jaddo ash.x.ash@hotmail.com wrote:
Hello,
I am using PJSIP 1.12.. I did not run any special config when I compiled the
libraries.. just compile for ARM6 and ARM7 then merge.. I am trying to get
background working so:
I used TCP instead of UDP as my protocol.
I checked PJ_ACTIVESOCK_TCP_IPHONE_OS_BG and
PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT in OS_autu.h and I see both of the
defined as 1. I see both of them defined in a “#if defined(PJ_DARWINOS) &&
PJ_DARWINOS!=0” so I did not change anything...
I added Required Background mode flag into my test App plist file
When I launch my app from xcode by hitting the run button, then I press home
on the device to put the app in background mode I see logs from my
registration function every 60 seconds as expected. and when I call the
device I hit the on_incomming_call event as expected....
But when I launch the app from the device itself just click on its icon the
background does not work..
if I tried to call the device after 60 seconds, Astersik will say the device
is not registered which mean the background socket did not respond to the
Keep alive message between the server and the device..if I removed the plist
entry about background mode It does not work in both cases (launch from
xcode and launch from device), so I think I am on the right path...
To confirm that my settings are good i added log success to “static void
activesock_create_iphone_os_stream(pj_activesock_t *asock)” when it set
kCFStreamNetworkServiceTypeVoIP and I see that log when I start the app from
xcode but again I know it is working from xcode but not as a stand alone..
Am I missing something else?? I have been researching this issue an I am not
sure what is missing? Anyone who did get background mode to work ??
Thanks,,,,,
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Thanks for your quick response..
I see what you are trying to get into but now I am lil bit confused about
how apple implemented this background mode..
From my understanding when Apple allowed (GPS, VOIP , AudioSessions) to run
in the background, in our case if I want use a socket I can mark my App as
VOIP then go an wrap my socket with kCFStreamNetworkServiceTypeVoIP... this
will tell Apple to report back to me anything come to this socket even if my
App is background.. so this is why I thought PJSIP did that wrapping for me
so all the INVITES from asterisk to keep registration alive and the incoming
calls will be passed to my App even if it is in background then I can use
local notification message to let the user know..
Am I Wrong? or iOS background mode and PJSIP background mode are completely
different?? I test a normal socket with background mode and it worked as I
understand it from Apple documentations and I did not have to do any keep
alive timer!!
Thank you again for you help and I really appreciate your support..
AsH
-----Original Message-----
From: Michael Fortson
Sent: Wednesday, February 08, 2012 12:26 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
Sorry, missed that you were using Asterisk now. But the first issue to
address is getting multitasking working on its own, and verifying that
the app is waking up every 10 minutes to re-register.
One more quick note about Xcode and app suspend: you need to lock the
screen after hitting the home button, in order to fully suspend the
app.
In the application delegate, here's how the sample app registers the
10 minute callback:
#define KEEP_ALIVE_INTERVAL 600
(void)applicationDidEnterBackground:(UIApplication *)application
{
[app performSelectorOnMainThread:@selector(keepAlive)
withObject:nil waitUntilDone:YES];
[application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{
[app performSelectorOnMainThread:@selector(keepAlive)
withObject:nil waitUntilDone:YES];
}];
}
(void)keepAlive {
NSlog(@"WAKE from sleep called");
if (!pj_thread_is_registered())
{
pj_thread_register("ipjsua", a_thread_desc, &a_thread);
}
pjsua_acc_set_registration(0, PJ_TRUE); //actually sends the
registration update
}
So the main tasks, in order, are:
And then:
On Wed, Feb 8, 2012 at 7:28 AM, Ashraf Jaddo ash.x.ash@hotmail.com wrote:
Hello,
I am using PJSIP 1.12.. I did not run any special config when I compiled
the
libraries.. just compile for ARM6 and ARM7 then merge.. I am trying to get
background working so:
I used TCP instead of UDP as my protocol.
I checked PJ_ACTIVESOCK_TCP_IPHONE_OS_BG and
PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT in OS_autu.h and I see both of the
defined as 1. I see both of them defined in a “#if defined(PJ_DARWINOS) &&
PJ_DARWINOS!=0” so I did not change anything...
I added Required Background mode flag into my test App plist file
When I launch my app from xcode by hitting the run button, then I press
home
on the device to put the app in background mode I see logs from my
registration function every 60 seconds as expected. and when I call the
device I hit the on_incomming_call event as expected....
But when I launch the app from the device itself just click on its icon
the
background does not work..
if I tried to call the device after 60 seconds, Astersik will say the
device
is not registered which mean the background socket did not respond to the
Keep alive message between the server and the device..if I removed the
plist
entry about background mode It does not work in both cases (launch from
xcode and launch from device), so I think I am on the right path...
To confirm that my settings are good i added log success to “static void
activesock_create_iphone_os_stream(pj_activesock_t *asock)” when it set
kCFStreamNetworkServiceTypeVoIP and I see that log when I start the app
from
xcode but again I know it is working from xcode but not as a stand alone..
Am I missing something else?? I have been researching this issue an I am
not
sure what is missing? Anyone who did get background mode to work ??
Thanks,,,,,
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
PJSIP wraps the socket, but that's just one part of it. Registrations
are kept alive from the client (via the KeepAliveTimeout method),
because that's the mobile part -- your IP address will change
periodically, and waking up every 10 minutes for a register call is
how you tell Asterisk where you are now (plus it's how you keep the
SIP registration active).
So just make sure you're really getting suspended (as noted before),
then make sure you're getting called every 10 minutes to wakeup and
re-register -- only after you know those are working should you look
further, to make sure the wake-on-incoming-call part is also working.
I know you've seen this link, but look at it again:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12
-- those first 4 steps are each critical. Wrapping is just one of them.
Thank you so much for your help.. I understand now what do, I will try this
and I will update if I got success.. I was confused because my test TCP
socket that I did to test background mode was working without doing any keep
alive. and I was getting notified if it received data so I thought PJSIP
will do the same automatically.
One last question, if my asterisk wants me to keep alive every 60 seconds.
what will happened if went to background mode and someone called me in 2
minutes.. this 8 minutes before my 10 minutes keep alive thread..
Best Regards,
-----Original Message-----
From: Michael Fortson
Sent: Wednesday, February 08, 2012 4:09 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
PJSIP wraps the socket, but that's just one part of it. Registrations
are kept alive from the client (via the KeepAliveTimeout method),
because that's the mobile part -- your IP address will change
periodically, and waking up every 10 minutes for a register call is
how you tell Asterisk where you are now (plus it's how you keep the
SIP registration active).
So just make sure you're really getting suspended (as noted before),
then make sure you're getting called every 10 minutes to wakeup and
re-register -- only after you know those are working should you look
further, to make sure the wake-on-incoming-call part is also working.
I know you've seen this link, but look at it again:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12
-- those first 4 steps are each critical. Wrapping is just one of them.
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
I started adding the keep alive code. where is app defined in:
[app performSelectorOnMainThread:@selector(keepAlive) withObject:nil
waitUntilDone:YES];
do you mean instead to use application??
also same for the next line..
about pj_thread_register("ipjsua", a_thread_desc, &a_thread); where do you
define a_thread_desc and a_thread? do I have to maintain
Thanks,
-----Original Message-----
From: Ashraf Jaddo
Sent: Wednesday, February 08, 2012 7:32 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
Thank you so much for your help.. I understand now what do, I will try this
and I will update if I got success.. I was confused because my test TCP
socket that I did to test background mode was working without doing any keep
alive. and I was getting notified if it received data so I thought PJSIP
will do the same automatically.
One last question, if my asterisk wants me to keep alive every 60 seconds.
what will happened if went to background mode and someone called me in 2
minutes.. this 8 minutes before my 10 minutes keep alive thread..
Best Regards,
-----Original Message-----
From: Michael Fortson
Sent: Wednesday, February 08, 2012 4:09 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
PJSIP wraps the socket, but that's just one part of it. Registrations
are kept alive from the client (via the KeepAliveTimeout method),
because that's the mobile part -- your IP address will change
periodically, and waking up every 10 minutes for a register call is
how you tell Asterisk where you are now (plus it's how you keep the
SIP registration active).
So just make sure you're really getting suspended (as noted before),
then make sure you're getting called every 10 minutes to wakeup and
re-register -- only after you know those are working should you look
further, to make sure the wake-on-incoming-call part is also working.
I know you've seen this link, but look at it again:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12
-- those first 4 steps are each critical. Wrapping is just one of them.
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
I just want to say thank you Michael I was able to get this to work :)
I configured asterisk to wait for 10 minutes for registration then in my
Keep alive function I was unregistering the current account and re register
with the same credential and it is working now..
Best Regards,
-----Original Message-----
From: Ashraf Jaddo
Sent: Thursday, February 09, 2012 10:40 AM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
I started adding the keep alive code. where is app defined in:
[app performSelectorOnMainThread:@selector(keepAlive) withObject:nil
waitUntilDone:YES];
do you mean instead to use application??
also same for the next line..
about pj_thread_register("ipjsua", a_thread_desc, &a_thread); where do you
define a_thread_desc and a_thread? do I have to maintain
Thanks,
-----Original Message-----
From: Ashraf Jaddo
Sent: Wednesday, February 08, 2012 7:32 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
Thank you so much for your help.. I understand now what do, I will try this
and I will update if I got success.. I was confused because my test TCP
socket that I did to test background mode was working without doing any keep
alive. and I was getting notified if it received data so I thought PJSIP
will do the same automatically.
One last question, if my asterisk wants me to keep alive every 60 seconds.
what will happened if went to background mode and someone called me in 2
minutes.. this 8 minutes before my 10 minutes keep alive thread..
Best Regards,
-----Original Message-----
From: Michael Fortson
Sent: Wednesday, February 08, 2012 4:09 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
PJSIP wraps the socket, but that's just one part of it. Registrations
are kept alive from the client (via the KeepAliveTimeout method),
because that's the mobile part -- your IP address will change
periodically, and waking up every 10 minutes for a register call is
how you tell Asterisk where you are now (plus it's how you keep the
SIP registration active).
So just make sure you're really getting suspended (as noted before),
then make sure you're getting called every 10 minutes to wakeup and
re-register -- only after you know those are working should you look
further, to make sure the wake-on-incoming-call part is also working.
I know you've seen this link, but look at it again:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12
-- those first 4 steps are each critical. Wrapping is just one of them.
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Great :) congrats!
--
Michael Fortson
On Thursday, February 16, 2012 at 1:04 PM, Ashraf Jaddo wrote:
I just want to say thank you Michael I was able to get this to work :)
I configured asterisk to wait for 10 minutes for registration then in my
Keep alive function I was unregistering the current account and re register
with the same credential and it is working now..
Best Regards,
-----Original Message-----
From: Ashraf Jaddo
Sent: Thursday, February 09, 2012 10:40 AM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
I started adding the keep alive code. where is app defined in:
[app performSelectorOnMainThread:@selector(keepAlive) withObject:nil
waitUntilDone:YES];
do you mean instead to use application??
also same for the next line..
about pj_thread_register("ipjsua", a_thread_desc, &a_thread); where do you
define a_thread_desc and a_thread? do I have to maintain
Thanks,
-----Original Message-----
From: Ashraf Jaddo
Sent: Wednesday, February 08, 2012 7:32 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
Thank you so much for your help.. I understand now what do, I will try this
and I will update if I got success.. I was confused because my test TCP
socket that I did to test background mode was working without doing any keep
alive. and I was getting notified if it received data so I thought PJSIP
will do the same automatically.
One last question, if my asterisk wants me to keep alive every 60 seconds.
what will happened if went to background mode and someone called me in 2
minutes.. this 8 minutes before my 10 minutes keep alive thread..
Best Regards,
-----Original Message-----
From: Michael Fortson
Sent: Wednesday, February 08, 2012 4:09 PM
To: pjsip list
Subject: Re: [pjsip] HELP about background mode
PJSIP wraps the socket, but that's just one part of it. Registrations
are kept alive from the client (via the KeepAliveTimeout method),
because that's the mobile part -- your IP address will change
periodically, and waking up every 10 minutes for a register call is
how you tell Asterisk where you are now (plus it's how you keep the
SIP registration active).
So just make sure you're really getting suspended (as noted before),
then make sure you're getting called every 10 minutes to wakeup and
re-register -- only after you know those are working should you look
further, to make sure the wake-on-incoming-call part is also working.
I know you've seen this link, but look at it again:
https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW12
-- those first 4 steps are each critical. Wrapping is just one of them.
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org (mailto:pjsip@lists.pjsip.org)
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org (mailto:pjsip@lists.pjsip.org)
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org (mailto:pjsip@lists.pjsip.org)
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
Visit our blog: http://blog.pjsip.org
pjsip mailing list
pjsip@lists.pjsip.org (mailto:pjsip@lists.pjsip.org)
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org