小编hwa*_*xer的帖子

UIApplication -canOpenURL:-openURL:返回误导性结果

从iOS6开始,我无法判断应用程序是否可以启动Safari.

如果Safari在设备上受到限制(设置>常规>限制),尝试打开URL时没有任何反应,并且没有指示出现了什么问题:

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
[[UIApplication sharedApplication] canOpenURL:url]; // Returns YES
[[UIApplication sharedApplication] openURL:url]; // Returns YES
Run Code Online (Sandbox Code Playgroud)

但是,Safari 无法启动,用户不知道为什么我的按钮"坏了".

这似乎是一个错误,所以我提交了一个雷达#12449905.

有没有其他方法可以解决这个问题?

uiapplication ios ios6

16
推荐指数
1
解决办法
4093
查看次数

重用NSMutableArray

在尝试重用现有的NSMutableArray时(为了节省内存),我得到了一些泄漏(由Instruments观察到).

基本上我正在创建一个NSMutableArray,用对象(UIImages)填充它并将它传递给另一个保留它的对象.但是,我现在需要再次使用NSMutableArray.我想我会释放它的所有对象,清空它,一切都会好的,但是仪器报告了一个CALayer泄漏的对象(??),该方法看起来如下:

NSString *fileName;
NSMutableArray *arrayOfImages = [[NSMutableArray alloc] init];

// fill the array with images
for(int i = 0; i <= 7; i++) {
    fileName = [NSString stringWithFormat:@"myImage_%d.png", i];
    [arrayOfImages addObject:[UIImage imageNamed:fileName]];
}

// create a button with the array
aButton = [[CustomButtonClass buttonWithType:UIButtonTypeCustom] 
                   initWithFrame:someFrame
                   imageArray:arrayOfImages];

// release its objects
for(int i = 0; i < [arrayOfImages count]; i++) {
    [[arrayOfImages objectAtIndex:i] release];
}
// empty array
[arrayOfImages removeAllObjects];

// fill it with other images
for(int i = 0; …
Run Code Online (Sandbox Code Playgroud)

cocoa release objective-c reusability nsmutablearray

1
推荐指数
1
解决办法
1569
查看次数

在UIAutomation中获取设备方向

我正在为我的程序编写自动化测试,并希望自动化设备方向......我使用下面的代码来设置设备的方向,

UIATarget.localTarget().setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT);
Run Code Online (Sandbox Code Playgroud)

但我也希望获得该设备的当前方向.我找不到任何getDeviceOrientation()方法来获取方向.

orientation device-orientation ios ios-ui-automation

0
推荐指数
1
解决办法
1267
查看次数