如何在主线程iOS

时间:2016-01-18 05:57:37

标签: ios pjsip

我已从此链接https://github.com/radif/SIPHON-SIP-Client-that-actually-compiles下载了源代码 当我编译然后我收到错误,请推荐我如何编译或我需要更改构建设置的架构

    /***** SIP ********/
/* */
- (BOOL)sipStartup
{
  if (_app_config.pool)
    return YES;

  self.networkActivityIndicatorVisible = YES;

  if (sip_startup(&_app_config) != PJ_SUCCESS)
  {
    self.networkActivityIndicatorVisible = NO;
    return NO;
  }
  self.networkActivityIndicatorVisible = NO;

  /** Call management **/
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(processCallState:)
                                               name: kSIPCallState object:nil];

  /** Registration management */
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(processRegState:)
                                               name: kSIPRegState object:nil];

  return YES;
}

/* */
- (void)sipCleanup
{
  //[[NSNotificationCenter defaultCenter] removeObserver:self];
  [[NSNotificationCenter defaultCenter] removeObserver:self
                                                  name: kSIPRegState
                                                object:nil];
  [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                  name:kSIPCallState 
                                                object:nil];
  [self sipDisconnect];

  if (_app_config.pool != NULL)
  {
    sip_cleanup(&_app_config);
  }
}

/* */
- (BOOL)sipConnect
{
  pj_status_t status;

  if (![self sipStartup])
    return FALSE;

  if ([self wakeUpNetwork] == NO)
    return NO;

  if (_sip_acc_id == PJSUA_INVALID_ID)
  {
    self.networkActivityIndicatorVisible = YES;
    if ((status = sip_connect(_app_config.pool, &_sip_acc_id)) != PJ_SUCCESS)
    {
      self.networkActivityIndicatorVisible = NO;
      return FALSE;
    }
  }

  return TRUE;
}

/* */
- (BOOL)sipDisconnect
{
  if ((_sip_acc_id != PJSUA_INVALID_ID) &&
      (sip_disconnect(&_sip_acc_id) != PJ_SUCCESS))
  {
    return FALSE;
  }

  _sip_acc_id = PJSUA_INVALID_ID;

  isConnected = FALSE;

  return TRUE;
}

- (void)initUserDefaults:(NSMutableDictionary *)dict fromSettings:(NSString *)settings
{
  NSDictionary *prefItem;

  NSString *pathStr = [[NSBundle mainBundle] bundlePath];
  NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"];
  NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:settings];
  NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:finalPath];
  NSArray *prefSpecifierArray = [settingsDict objectForKey:@"PreferenceSpecifiers"];

  for (prefItem in prefSpecifierArray)
  {
    NSString *keyValueStr = [prefItem objectForKey:@"Key"];
    if (keyValueStr)
    {
      id defaultValue = [prefItem objectForKey:@"DefaultValue"];
      if (defaultValue)
      {
        [dict setObject:defaultValue forKey: keyValueStr];
      }
    }
  }
}

- (void)initUserDefaults
{
#if defined(CYDIA) && (CYDIA == 1)
  // TODO Franchement pas beau ;-)
  NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
  NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                        [NSNumber numberWithInt: 1800], @"regTimeout",
                        [NSNumber numberWithBool:NO], @"enableNat",
                        [NSNumber numberWithBool:NO], @"enableMJ",
                        [NSNumber numberWithInt: 5060], @"localPort",
                        [NSNumber numberWithInt: 4000], @"rtpPort",
                        [NSNumber numberWithInt: 15], @"kaInterval",
                        [NSNumber numberWithBool:NO], @"enableEC",
                        [NSNumber numberWithBool:YES], @"disableVad",
                        [NSNumber numberWithInt: 0], @"codec",
                        [NSNumber numberWithBool:NO], @"dtmfWithInfo",
                        [NSNumber numberWithBool:NO], @"enableICE",
                        [NSNumber numberWithInt: 0], @"logLevel",
                        [NSNumber numberWithBool:YES],  @"enableG711u",
                        [NSNumber numberWithBool:YES],  @"enableG711a",
                        [NSNumber numberWithBool:NO],   @"enableG722",
                        [NSNumber numberWithBool:NO],   @"enableG7221",
                        [NSNumber numberWithBool:NO],   @"enableG729",
                        [NSNumber numberWithBool:YES],  @"enableGSM",
                        [NSNumber numberWithBool:NO], @"keepAwake",
                        nil];

  [userDef registerDefaults:dict];
  [userDef synchronize];
#else
  NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];

  NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity: 10];
  [self initUserDefaults:dict fromSettings:@"Advanced.plist"];
  [self initUserDefaults:dict fromSettings:@"Network.plist"];
  [self initUserDefaults:dict fromSettings:@"Phone.plist"];
  [self initUserDefaults:dict fromSettings:@"Codec.plist"];

  [userDef registerDefaults:dict];
  [userDef synchronize];
  //[dict release];
#endif // CYDIA
}

- (void)initModel
{
  NSString *model = [[UIDevice currentDevice] model];
  isIpod = [model hasPrefix:@"iPod"];
  //NSLog(@"%@", model);
}

- (UIView *)applicationStartWithoutSettings
  {    
    // TODO: go to settings immediately
    UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
                                                      applicationFrame]];
    mainView.backgroundColor = [UIColor whiteColor];

    UINavigationBar *navBar = [[UINavigationBar alloc] init];
    [navBar setFrame:CGRectMake(0, 0, 320,45)];
    navBar.barStyle = UIBarStyleBlackOpaque;
    [navBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle:VERSION_STRING]
                                 animated: NO];
    [mainView addSubview:navBar];

    UIImageView *background = [[UIImageView alloc]
      initWithFrame:CGRectMake(0.0f, 45.0f, 320.0f, 185.0f)];
    [background setImage:[UIImage imageNamed:@"settings.png"]];
    [mainView addSubview:background];

    UILabel *text = [[UILabel alloc]
      initWithFrame: CGRectMake(0, 220, 320, 200.0f)];
    text.backgroundColor = [UIColor clearColor];
    text.textAlignment = UITextAlignmentCenter;
    text.numberOfLines = 0;
    text.lineBreakMode = UILineBreakModeWordWrap;
    text.font = [UIFont systemFontOfSize: 18];
    text.text = NSLocalizedString(@"Siphon requires a valid\nSIP account.\n\nTo enter this information, select \"Settings\" from your Home screen, and then tap the \"Siphon\" entry.", @"SiphonApp");
    [mainView addSubview:text];

    text = [[UILabel alloc] initWithFrame: CGRectMake(0, 420, 320, 40.0f)];
    text.backgroundColor = [UIColor clearColor];
    text.textAlignment = UITextAlignmentCenter;
    text.font = [UIFont systemFontOfSize: 16];
    text.text = NSLocalizedString(@"Press the Home button", @"SiphonApp");
    [mainView addSubview:text];

  return mainView;
}

- (UIView *)applicationStartWithSettings
    {
    /* Favorites List*/
        /*
    FavoritesListController *favoritesListCtrl = [[FavoritesListController alloc]
                                                  initWithStyle:UITableViewStylePlain];
                                                  //autorelease];
    favoritesListCtrl.phoneCallDelegate = self;

    UINavigationController *favoritesViewCtrl = [[[UINavigationController alloc]
                                                   initWithRootViewController:
                                                   favoritesListCtrl]
                                                  autorelease];
    favoritesViewCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
    [favoritesListCtrl release];
*/
    /* Recents list */
    recentsViewController = [[RecentsViewController alloc]
                              initWithStyle:UITableViewStylePlain];
                                             //autorelease];
    recentsViewController.phoneCallDelegate = self;
    UINavigationController *recentsViewCtrl = [[[UINavigationController alloc]
                                                   initWithRootViewController:
                                                   recentsViewController]
                                                  autorelease];
    recentsViewCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
    [recentsViewController release];

    /* Dialpad */
    phoneViewController = [[[PhoneViewController alloc]
                            initWithNibName:nil bundle:nil] autorelease];
    phoneViewController.phoneCallDelegate = self;

    /* Contacts */
    ContactViewController *contactsViewCtrl = [[[ContactViewController alloc]
                                                init] autorelease];
    contactsViewCtrl.phoneCallDelegate = self;

    /* Voicemail */
    VoicemailController *voicemailController = [[VoicemailController alloc]
                                                initWithStyle:UITableViewStyleGrouped];
    voicemailController.phoneCallDelegate = self;
    UINavigationController *voicemailNavCtrl = [[[UINavigationController alloc]
                                                initWithRootViewController:
                                                voicemailController]
                                               autorelease];
    voicemailNavCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
    [voicemailController release];

    tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:
                                        /*favoritesViewCtrl,*/ recentsViewCtrl,
                                        phoneViewController, contactsViewCtrl, 
                                        voicemailNavCtrl, nil];
    tabBarController.selectedIndex = 2;

  return tabBarController.view;
}

/***** APPLICATION *****/
#if 0 //def __IPHONE_3_0
- (BOOL)application:(UIApplication *)application 
      didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if (launchOptions == nil)
  {
    // Démarrage normal
  }
  NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
  // UIApplicationLaunchOptionsSourceApplicationKey : Pour retrouver l'appli qui lance
  if (url != nil)
  {
    // Démarrage avec URL
  }
  NSDictionary *userInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
  if (userInfo != nil)
  {
    // Réception d'une notification
  }
}
/* Sent to the delegate when a running application receives a remote notification.
 * RQ: Ne devrais pas être appelée, le serveur ne devrait pas communiquer avec une 
 *     application lancée.
 * RQ: Une appli peut être lancée sans être connectée au serveur (absence de WiFi)
 */
- (void)application:(UIApplication *)application 
      didReceiveRemoteNotification:(NSDictionary *)userInfo
{

}
#else
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
#if defined(CYDIA) && (CYDIA == 1)
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  NSString *libraryDirectory = [NSString stringWithFormat:@"%@/Siphon", [paths objectAtIndex:0]];
  mkdir([libraryDirectory UTF8String], 0755);
#endif

  _sip_acc_id = PJSUA_INVALID_ID;

  isConnected = FALSE;

  [self initModel];

  self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

  NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
  [self initUserDefaults];

    if (![[userDef objectForKey: @"username"] length] ||
        ![[userDef objectForKey: @"server"] length])
  {
     // self.window.rootViewController = navigationController;

    [window addSubview: [self applicationStartWithoutSettings]];
     // window.rootViewController=[self applicationStartWithoutSettings] ;
    //[window makeKeyAndVisible];

    launchDefault = NO;
  }
  else
  {
    NSString *server = [userDef stringForKey: @"proxyServer"];
    NSArray *array = [server componentsSeparatedByString:@","];
    NSEnumerator *enumerator = [array objectEnumerator];
    while (server = [enumerator nextObject]) 
      if ([server length])break;// {[server retain]; break;}
    //[enumerator release];
   // [array release];
    if (!server || [server length] < 1)
      server = [userDef stringForKey: @"server"];

    NSRange range = [server rangeOfString:@":" 
                                  options:NSCaseInsensitiveSearch|NSBackwardsSearch];
    if (range.length > 0)
    {
      server = [server substringToIndex:range.location];
    }

    // Build GUI
    callViewController = [[CallViewController alloc] initWithNibName:nil bundle:nil];

    [window addSubview: [self applicationStartWithSettings]];
    //[window makeKeyAndVisible];

   [[NSNotificationCenter defaultCenter] addObserver:self 
                                            selector:@selector(reachabilityChanged:) 
                                                 name:kReachabilityChangedNotification 
                                              object:nil];
    _hostReach = [[Reachability reachabilityWithHostName: server] retain];
    [_hostReach startNotifer];

    launchDefault = YES;
    [self performSelector:@selector(sipConnect) withObject:nil afterDelay:0.2];

    if ([userDef boolForKey:@"keepAwake"])
      [self keepAwakeEnabled];
  }

  [window makeKeyAndVisible];
}
#endif

i am getting this error when compiled

2 个答案:

答案 0 :(得分:0)

只需转到编辑 - &gt;转换 - &gt;用于添加弧的物镜c弧。

答案 1 :(得分:0)

我需要更改主文件

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}