如何以编程方式关闭系统对话框,如“<app>想要访问您的照片”?</app>

时间:2013-10-09 17:51:38

标签: iphone objective-c dialog

有没有办法以编程方式解除对话框,例如应用想要访问照片,访问联系人和访问位置的对话框?

我认为通过混合API方法有一种方法,但我真的不知道哪种方法。找出哪些方法需要调整的方法是什么?如果不是那种混合方式那么可能是另一种选择呢?

作为一个注释,这不是一个产品,只是为了测试,如果它工作,调配是一个很好的选择。

2 个答案:

答案 0 :(得分:0)

您应该可以从应用中的任何位置访问此类提醒。这适用于常规警报,但我没有尝试使用系统警报(有可能它们与常规警报不在同一层次结构中,在这种情况下,您根本无法访问它们)。如果它确实有效并且您尝试使用此版本发布应用程序,则几乎肯定会被拒绝。

for (UIWindow* w in [UIApplication sharedApplication].windows)
{
    for (NSObject* o in w.subviews)
        if ([o isKindOfClass:[UIAlertView class]])
        {
            // as an example, this will just dismiss/cancel the alert
            [(UIAlertView*)o dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
        }
}

答案 1 :(得分:0)

1。覆盖&#34;访问联系人&#34;对话框

UIApplicationDelegate实施中输入此代码(必须导入<AddressBook/AddressBook.h>

ABAuthorizationStatus ABAddressBookGetAuthorizationStatus(void) {
  return kABAuthorizationStatusAuthorized;
}

2。创建一个混合方法:

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。覆盖&#34;访问位置&#34;对话框:

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。覆盖&#34;访问照片&#34;对话框:

UIApplicationDelegate实施中执行以下操作。 (需要导入<AssetsLibrary/AssetsLibrary.h>):

[self swizzleSelector:@selector(authorizationStatus) fromClass:[ALAssetsLibrary class] withBlock:^{ return ALAuthorizationStatusAuthorized; }];
[self swizzleSelector:@selector(enumerateGroupsWithTypes:usingBlock:failureBlock:) fromInstancesOfClass:[ALAssetsLibrary class] withBlock:^{}];