2014-10-20 15 views
0

嗨我目前正在为客户的项目工作,我需要访问电话联系人。在ButtonAction上访问联系人并执行Segue

我设法要求允许访问联系人,我处理两种不同的状态(授予,拒绝)。 显然,客户希望下面的工作流程:

  • 创下添加按钮
  • 要求允许
  • 授予: 执行SEGUE与上市
  • 否认所有接触tablewview:执行顺着接下去一个不同的观点,并不断询问初始按钮命中授予访问联系人

我管理完整的流程,并提取了c完整的数据。没有I M卡有两个问题:

  1. 我不能得到申请许可alertview再次弹出的(从 我了解用户需要设置这在应用程序 设置 - >应用隐私设置)。它是否正确?
  2. 看来,如果访问被授予第一次,我 执行segue tableview是空的,因为数据数组是无 (我不明白为什么)。
- (void)addButtonTouched { 
[self.addressBook accessAddressBook]; 
[self.activityView startActivityViewWithMessage:@"Wait a second"]; 
if (access) { 
    self.contactsArray = [self.addressBook getAllContacts]; 
    if (self.contactsArray.count != 0) { 
     [self performSegueWithIdentifier:@"addEntrySegue" sender:self]; 
    } else { 
     [self performSegueWithIdentifier:@"noContactsSegue" sender:self]; 
    } 
} 

我是不是推动尽快到下一个视图控制器来填补self.contactsArray

我的另一种方法是在授予访问权限后向我的rootViewController发送Notificaion,然后执行segue。这是我能得到的最接近的结果,但ViewController推迟了8-10秒。

>  - (void)receivedNotification:(NSNotification *)notification { 
>   if (access) { 
>    self.contactsArray = [self.addressBook getAllContacts]; 
>    if (self.contactsArray.count != 0) { 
>     [self performSegueWithIdentifier:@"addEntryrSegue" sender:self]; 
>    } else { 
>     [self performSegueWithIdentifier:@"noContactsSegue" sender:self]; 
>    } 
>   } 
>  } 

在此先感谢。我希望我解释得很好。

回答

0
  1. 是的。用户必须从设置中手动重新启用它。您最好的选择可能是创建替代视图,并指示如何接受它。

  2. 该数组充满了所有联系人。你想确保你做了两件事。一:在表上reloadData()。二:确保正确处理异步操作。因此,处理此问题的最佳方法是运行如下代码:

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul); 
    dispatch_async(queue, ^{ 
        // Fill array with contacts here. Run the function. Whatever you need to do goes here. 
          dispatch_sync(dispatch_get_main_queue(), ^{ 
           // Reload the table. Whatever UI changes you want go here. 
          }); 
    });