Ignore:
Timestamp:
Sep 15, 2017 5:32:08 AM (7 years ago)
Author:
riza
Message:

Re #2041: Implement API to handle IP address change.

File:
1 edited

Legend:

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

    r5628 r5649  
    2828 
    2929#import "ipjsuaViewController.h" 
     30#import "Reachability.h" 
    3031 
    3132@implementation ipjsuaAppDelegate 
     
    4041static char           **restartArgv; 
    4142static int              restartArgc; 
     43Reachability            *internetReach; 
     44 
     45- (void) updateWithReachability: (Reachability *)curReach 
     46{ 
     47    NetworkStatus netStatus = [curReach currentReachabilityStatus]; 
     48    BOOL connectionRequired = [curReach connectionRequired]; 
     49    switch (netStatus) { 
     50        case NotReachable: 
     51            PJ_LOG(3,("", "Access Not Available..")); 
     52            connectionRequired= NO; 
     53            break; 
     54        case ReachableViaWiFi: 
     55            PJ_LOG(3,("", "Reachable WiFi..")); 
     56            break; 
     57        case ReachableViaWWAN: 
     58            PJ_LOG(3,("", "Reachable WWAN..")); 
     59        break; 
     60    } 
     61    if (connectionRequired) { 
     62        PJ_LOG(3,("", "Connection Required")); 
     63    } 
     64} 
     65 
     66/* Called by Reachability whenever status changes. */ 
     67- (void)reachabilityChanged: (NSNotification *)note 
     68{ 
     69    Reachability* curReach = [note object]; 
     70    NSParameterAssert([curReach isKindOfClass: [Reachability class]]); 
     71    PJ_LOG(3,("", "reachability changed..")); 
     72    [self updateWithReachability: curReach]; 
     73     
     74    if ([curReach currentReachabilityStatus] != NotReachable && 
     75        ![curReach connectionRequired]) 
     76    { 
     77        pjsua_ip_change_param param; 
     78        pjsua_ip_change_param_default(&param); 
     79        pjsua_handle_ip_change(&param); 
     80    } 
     81} 
     82 
    4283 
    4384void displayLog(const char *msg, int len) 
     
    155196    self.window.rootViewController = self.viewController; 
    156197    [self.window makeKeyAndVisible]; 
     198     
     199    /* Observe the kNetworkReachabilityChangedNotification. When that 
     200     * notification is posted, the method "reachabilityChanged" will be called. 
     201     */ 
     202    [[NSNotificationCenter defaultCenter] addObserver: self 
     203          selector: @selector(reachabilityChanged:) 
     204          name: kReachabilityChangedNotification object: nil]; 
     205     
     206    internetReach = [Reachability reachabilityForInternetConnection]; 
     207    [internetReach startNotifier]; 
     208    [self updateWithReachability: internetReach]; 
    157209     
    158210    app = self; 
Note: See TracChangeset for help on using the changeset viewer.