アプリケーションの tableView にアドレス帳データを取得しました。このコードはシミュレータで正常に実行されています。シミュレーターのアプリの tableView で連絡先のデータを取得しましたが、デバイスでこれをテストすると、連絡先のデータが取得されませんでした。6.1 シミュレーターと iPhone デバイス ios 6.1.3 を使用しました。このコードの実際の問題は何ですか? このコードはシミュレーターで正常に実行されますが、コードは iPhone デバイス iOS 6.1.3 では実行されませんでした
ありがとうございます
ClsMainPageAppDelegate.h
#import <UIKit/UIKit.h>
#import "Person.h"
@interface ClsMainPageAppDelegate : UIResponder <UIApplicationDelegate>
{
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) Person *objPerson;
@end
ClsMainPageAppDelegate.m
#import "ClsMainPageAppDelegate.h"
#import "ClsMainPageViewController.h"
@implementation ClsMainPageAppDelegate
@synthesize objPerson;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
}
Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSString *fullName;
@property (nonatomic, strong) NSString *phoneNumber;
@property (nonatomic, strong) NSString *workEmail;
@end
人.m
#import "Person.h"
@implementation Person
- (id)init
{
self = [super init];
if (self)
{
}
return self;
}
@end
ClsAddressBookViewController.h
#import <UIKit/UIKit.h>
@interface ClsAddressBookViewController : UIViewController
- (IBAction)backcontacts:(id)sender;
@end
ClsAddressBookViewController.m
#import "ClsAddressBookViewController.h"
#import "ClsUpdateNetworkViewController.h"
#import "ClsMainPageAppDelegate.h"
#import "Person.h"
#import <AddressBook/AddressBook.h>
@interface ClsAddressBookViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *tableData;
@end
@implementation ClsAddressBookViewController
@synthesize tableData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"Contacts";
self.tableData = [[NSMutableArray alloc]init];
[self getPersonOutOfAddressBook];
}
- (void)getPersonOutOfAddressBook
{
CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (addressBook != nil)
{
NSLog(@"Succesful.");
NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSUInteger i = 0;
for (i = 0; i < [allContacts count]; i++)
{
Person *person = [[Person alloc] init];
ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);
NSString *fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
person.firstName = firstName;
person.lastName = lastName;
person.fullName = fullName;
//Mobile Number
ABMultiValueRef mobilenum = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);
NSUInteger k = 0;
for(k = 0; k < ABMultiValueGetCount(mobilenum); k++)
{
NSString *mobile = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(mobilenum, k);
if(k == 0)
{
person.phoneNumber = mobile;
NSLog(@"person.mobilenum = %@", person.phoneNumber);
}
else if (k==1)
person.phoneNumber = mobile;
}
[self.tableData addObject:person];
}
}
CFRelease(addressBook);
}
#pragma mark TableView Delegate
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableData count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Person *person = [self.tableData objectAtIndex:indexPath.row];
cell.textLabel.text = person.fullName;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Person *person = [self.tableData objectAtIndex:indexPath.row];
ClsMainPageAppDelegate *objdelegate = [[UIApplication sharedApplication]delegate];
objdelegate.objPerson = person;
UIStoryboard *storybrd = self.storyboard;
ClsAddressBookViewController *svc = [storybrd instantiateViewControllerWithIdentifier:@"clsUpdatecontrol"];
[self presentViewController:svc animated:YES completion:nil ];
}