Objective C: Bring back user to your application during/after he End the Call

Sometime you need come back to application after phone call initiated by your own application.
Exist two options (each from them not 100% that do you want), but if no choice..

  1. After starting phone call you getting local notification alert with two option
    • Cancel (stay on call screen)
    • Return (back to application during your call)
    NSURL *phoneSchemaURL = [NSURL URLWithString:@"tel://123456789"];
     
    [[UIApplication sharedApplication] openURL:phoneSchemaURL];
    
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    if (localNotification != nil) {
     NSDate *notificationDate = [[NSDate alloc] initWithTimeIntervalSinceNow: 3];
      
     localNotification.fireDate = notificationDate;
     [notificationDate release];
      
     localNotification.alertBody = @"Stay in app";
     localNotification.alertAction = @"Return";
      
     localNotification.soundName = UILocalNotificationDefaultSoundName;
      
     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    }
    [localNotification release];
    
  2. After ending phone call your application retrieve focus.
    NSURL *phoneSchemaURL = [NSURL URLWithString:@"tel://123456789"];
     
     NSString *osVersion = [[UIDevice currentDevice] systemVersion];
     
    if([osVersion compare: @"3.1" options: NSNumericSearch] >= NSOrderedSame ) {
     UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
     //or if you just want to call and back to application
     //UIWebView *webview = [[UIWebView alloc] init];
    
     [webview loadRequest:[NSURLRequest requestWithURL:phoneSchemaURL]];
      
     //if you just want to call and back to application remark code below, but don't forget release webview
     [self.view addSubview:webview];
     [webview release];
    } else {
     // On 3.0 and below, dial as usual
     [[UIApplication sharedApplication] openURL: phoneSchemaURL];          
    }
    

No comments:

Post a Comment