【发布时间】:2013-03-21 21:16:54
【问题描述】:
我正在使用 KIF 进行 GUI 测试,我们似乎无法在 Simulator 中自动单击应用程序首次运行时出现的 <app> would like to use your current location 警报中的 OK 按钮。有没有办法配置模拟器或应用程序来绕过该弹出窗口?
【问题讨论】:
标签: ios ios-simulator kif-framework
我正在使用 KIF 进行 GUI 测试,我们似乎无法在 Simulator 中自动单击应用程序首次运行时出现的 <app> would like to use your current location 警报中的 OK 按钮。有没有办法配置模拟器或应用程序来绕过该弹出窗口?
【问题讨论】:
标签: ios ios-simulator kif-framework
recent addition 到 KIF 将 -acknowledgeSystemAlert 添加到测试运行器。这可以在模拟器上运行以确认位置服务授权对话框时使用。当请求访问用户的照片库时,可以以相同的方式使用它。
【讨论】:
有一个thread about this on the KIF mailing list about a year ago。
由于您这样做只是为了测试,因此很容易调出CLLocationManager 的部分以避免此警报。
(显然,任何提交到应用商店的代码都会让你匆忙拒绝。)
[CLLocationManager swizzleInstanceSelector:@selector(startUpdatingLocationFake) toSelector:@selector(startUpdatingLocation)];
[CLLocationManager swizzleInstanceSelector:@selector(locationFake) toSelector:@selector(location)];
// One for class, one for (deprecated) instance method
[CLLocationManager swizzleInstanceSelector:@selector(locationServicesEnabledFake) toSelector:@selector(locationServicesEnabled)];
[CLLocationManager swizzleClassSelector:@selector(locationServicesEnabledFake) toSelector:@selector(locationServicesEnabled)];
这两个新的类方法定义如下:
+ (void)swizzleInstanceSelector:(SEL)firstSelector toSelector:(SEL)secondSelector;
{
Method swizzleMethod = class_getInstanceMethod(self, firstSelector);
Method method = class_getInstanceMethod(self, secondSelector);
method_exchangeImplementations(method, swizzleMethod);
}
+ (void)swizzleClassSelector:(SEL)firstSelector toSelector:(SEL)secondSelector;
{
Method swizzleMethod = class_getClassMethod(self, firstSelector);
Method method = class_getClassMethod(self, secondSelector);
method_exchangeImplementations(method, swizzleMethod);
}
【讨论】: