0

我正在用 theos 编译这个调整。我正在尝试在 iPhone 的控制中心内制作一个按钮,按下该按钮会显示联系人列表。我究竟做错了什么?

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

@interface SBAppSliderScrollingViewController : UIViewController
@property (nonatomic, strong) UIButton *button;
-(void)loadView;
@end

%hook SBAppSliderScrollingViewController

-(void)viewDidLoad {
   %orig;
   UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   [button setTitle:@"Contacts" forState:UIControlStateNormal]; 
   button.frame = CGRectMake(-25, 7, 150, 37);
   [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
   [self.view addSubview:button]; 
}

%new
-(void)buttonPressed:(id)sender {
    ABPeoplePickerNavigationController *peoplePicker = 
    [[ABPeoplePickerNavigationController alloc] init];
     peoplePicker.peoplePickerDelegate = self;
     [self presentModalViewController:peoplePicker animated:YES];
}

%end

这是我的生成文件:

ARCHS = armv7 arm64
include theos/makefiles/common.mk

TWEAK_NAME = Contacts
Contacts_FILES = Tweak.xm
Contacts_FRAMEWORKS = UIKit
Contacts_FRAMEWORKS = AddressBook
Contacts_FRAMEWORKS = AddressBookUI

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
    install.exec "killall -9 SpringBoard; killall -9 backboardd"

这是我在使用 theos 编译调整时遇到的错误:

Brandons-Mac:contacts root# make package
Making all for tweak Contacts...
 Preprocessing Tweak.xm...
 Compiling Tweak.xm...
Tweak.xm:26:37: error: assigning to
      'id<ABPeoplePickerNavigationControllerDelegate>' from incompatible type
      'CKTranscriptCollectionViewController *'
         peoplePicker.peoplePickerDelegate = self;
                                           ^ ~~~~
1 error generated.
make[2]: *** [obj/Tweak.xm.d559d84f.o] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [Contacts.all.tweak.variables] Error 2
Brandons-Mac:contacts root# 
4

1 回答 1

0

你有没有实现它的委托方法。?

你应该写

@interface SBAppSliderScrollingViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate >

现在实现 ABPeoplePickerNavigationController 的 Delegate 方法

 -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
    return YES;
}
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    // ensure user picked a phone property
    if(property == kABPersonPhoneProperty)
    {
        ABMultiValueRef phone = ABRecordCopyValue(person, property);
        NSString *phn = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phone, ABMultiValueGetIndexForIdentifier(phone, identifier));
        //Your phone no
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else{

    }
    /* Display message if selection is not a phone number */

        return NO;
}
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
    [self dismissViewControllerAnimated:YES completion:nil];
}

第二件事你不应该使用[self presentModalViewController:peoplePicker animated:YES]; 而不是使用

[self presentViewController:peoplePicker animated:YES completion:nil];
于 2014-09-25T05:02:15.997 回答