4

我正在使用 KIF 进行 GUI 测试,似乎我们无法在 Simulator 中自动单击<app> would like to use your current location应用程序首次运行时出现的警报中的 OK 按钮。有没有办法配置模拟器或应用程序来绕过该弹出窗口?

4

2 回答 2

3

最近添加到 KIF 的内容增加-acknowledgeSystemAlert了测试运行程序。这可以在模拟器上运行以确认位置服务授权对话框时使用。当请求访问用户的照片库时,可以以相同的方式使用它。

于 2014-12-15T19:52:47.137 回答
2

大约一年前,KIF 邮件列表上有一个关于此的主题。

由于您这样做只是为了测试,因此很容易调出 的部分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);
}
于 2013-03-22T00:41:40.223 回答