1。覆盖“访问联系人”对话框
在您的 UIApplicationDelegate 实现中键入此代码(需要导入 <AddressBook/AddressBook.h>:
ABAuthorizationStatus ABAddressBookGetAuthorizationStatus(void) {
return kABAuthorizationStatusAuthorized;
}
2。创建一个 swizzling 方法:
在您的UIApplicationDelegate 实现中输入以下方法,或者在您需要的任何地方,最好使用辅助类。 (需要导入<objc/runtime.h>:
- (void)swizzleSelector:(SEL)selector fromInstancesOfClass:(Class)clazz withBlock:(id)block {
id replaceBlock = Block_copy(block);
Method origMethod = class_getInstanceMethod(clazz, selector);
IMP origImpl = method_getImplementation(origMethod);
IMP replaceImpl = imp_implementationWithBlock(replaceBlock);
method_setImplementation(origMethod, replaceImpl);
}
- (void)swizzleSelector:(SEL)selector fromClass:(Class)clazz withBlock:(id)block {
id replaceBlock = Block_copy(block);
Method origMethod = class_getClassMethod(clazz, selector);
IMP origImpl = method_getImplementation(origMethod);
IMP replaceImpl = imp_implementationWithBlock(replaceBlock);
method_setImplementation(origMethod, replaceImpl);
}
3。覆盖“访问位置”对话框:
在您的 UIApplicationDelegate 实现中执行以下操作。 (需要导入<CoreLocation/CoreLocation.h>):
[self swizzleSelector:@selector(startUpdatingLocation) fromInstancesOfClass:[CLLocationManager class] withBlock:^{}];
[self swizzleSelector:@selector(startMonitoringSignificantLocationChanges) fromInstancesOfClass:[CLLocationManager class] withBlock:^{}];
[self swizzleSelector:@selector(locationServicesEnabled) fromClass:[CLLocationManager class] withBlock:^{ return NO; }];
4。覆盖“访问照片”对话框:
在您的 UIApplicationDelegate 实施中执行以下操作。 (需要导入<AssetsLibrary/AssetsLibrary.h>):
[self swizzleSelector:@selector(authorizationStatus) fromClass:[ALAssetsLibrary class] withBlock:^{ return ALAuthorizationStatusAuthorized; }];
[self swizzleSelector:@selector(enumerateGroupsWithTypes:usingBlock:failureBlock:) fromInstancesOfClass:[ALAssetsLibrary class] withBlock:^{}];