Ignore:
Timestamp:
Aug 27, 2010 6:46:29 AM (14 years ago)
Author:
ming
Message:

Closed ticket #1107: iOS4 background feature

  • pjlib:
    • add support for activesock TCP to work in background mode.
    • add feature in ioqueue to recreate closed UDP sockets.
  • pjsip-apps:
    • ipjsua: add support for iPhone OS 4 background mode
    • ipjsystest: add support for iPhone OS 4 background mode
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m

    r3258 r3299  
    88 
    99#import <pjlib.h> 
     10#import <pjsua.h> 
    1011#import "ipjsuaAppDelegate.h" 
    1112 
     
    1920 
    2021/* Sleep interval duration */ 
    21 #define SLEEP_INTERVAL  0.5 
     22#define SLEEP_INTERVAL      0.5 
    2223/* Determine whether we should print the messages in the debugger 
    2324 * console as well 
    2425 */ 
    25 #define DEBUGGER_PRINT  1 
     26#define DEBUGGER_PRINT      1 
    2627/* Whether we should show pj log messages in the text area */ 
    27 #define SHOW_LOG        1 
    28 #define PATH_LENGTH     PJ_MAXPATH 
     28#define SHOW_LOG            1 
     29#define PATH_LENGTH         PJ_MAXPATH 
     30#define KEEP_ALIVE_INTERVAL 600 
    2931 
    3032extern pj_bool_t app_restart; 
     
    3537ipjsuaAppDelegate       *app; 
    3638 
    37 bool                    app_running; 
    38 bool                    thread_quit; 
     39bool                     app_running; 
     40bool                     thread_quit; 
    3941NSMutableString         *mstr; 
     42pj_thread_desc           a_thread_desc; 
     43pj_thread_t             *a_thread; 
     44pjsua_call_id            ccall_id; 
    4045 
    4146pj_status_t app_init(int argc, char *argv[]); 
    4247pj_status_t app_main(void); 
    4348pj_status_t app_destroy(void); 
     49void keepAliveFunction(int timeout); 
    4450 
    4551void showMsg(const char *format, ...) 
     
    5157    NSString *str = [[NSString alloc] initWithFormat:[NSString stringWithFormat:@"%s", format] arguments: arg]; 
    5258#if DEBUGGER_PRINT 
    53     NSLog(str); 
     59    NSLog(@"%@", str); 
    5460#endif 
    5561    va_end(arg); 
     
    9298    showMsg("%s", data); 
    9399} 
     100 
     101pj_bool_t showNotification(pjsua_call_id call_id) 
     102{ 
     103#ifdef __IPHONE_4_0 
     104    ccall_id = call_id; 
     105 
     106    // Create a new notification 
     107    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     108    UILocalNotification* alert = [[[UILocalNotification alloc] init] autorelease]; 
     109    if (alert) 
     110    { 
     111        alert.repeatInterval = 0; 
     112        alert.alertBody = @"Incoming call received..."; 
     113        alert.alertAction = @"Answer"; 
     114         
     115        [[UIApplication sharedApplication] presentLocalNotificationNow:alert]; 
     116    } 
     117     
     118    [pool release]; 
     119     
     120    return PJ_FALSE; 
     121#else 
     122    return PJ_TRUE; 
     123#endif 
     124} 
     125 
     126- (void)answer_call { 
     127    if (!pj_thread_is_registered()) 
     128    { 
     129        pj_thread_register("ipjsua", a_thread_desc, &a_thread); 
     130    } 
     131    pjsua_call_answer(ccall_id, 200, NULL, NULL); 
     132} 
     133 
     134#ifdef __IPHONE_4_0 
     135- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 
     136    [app performSelectorOnMainThread:@selector(answer_call) withObject:nil waitUntilDone:YES]; 
     137} 
     138 
     139- (void)keepAlive { 
     140    if (!pj_thread_is_registered()) 
     141    { 
     142        pj_thread_register("ipjsua", a_thread_desc, &a_thread); 
     143    }     
     144    keepAliveFunction(KEEP_ALIVE_INTERVAL); 
     145} 
     146 
     147- (void)applicationDidEnterBackground:(UIApplication *)application 
     148{ 
     149    [app performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES]; 
     150    [application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{ 
     151        [app performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES]; 
     152    }]; 
     153} 
     154 
     155#endif 
    94156 
    95157- (void)start_app { 
Note: See TracChangeset for help on using the changeset viewer.