小编AJ9*_*AJ9的帖子

是否有tvOS的模拟器?

是否有tvOS的模拟器?

我作为默认项目的一部分获得的是"Generic tvOS Device"

通用tvOS

错误:

错误

xcode tvos

11
推荐指数
2
解决办法
4086
查看次数

iCloud UIDocumentPicker间歇性崩溃并挂起

问题:

当从iCloud中选择文档时,应用程序会随机崩溃,大多数时候以下代码都会起作用,但在极少数情况下会失败.

我在应用程序中启用了iCloud权利,似乎无法找到间歇性失败的原因.有检查我错过了吗?

它也会偶尔悬挂5秒钟左右(通常在碰撞中)

码:

#pragma mark - iCloud =======================================================================================================
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {

BOOL fileUrlAuthozied = [url startAccessingSecurityScopedResource];
NSURL *ubiquityURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSLog(@"ubiquityURL - %@",ubiquityURL);

if(fileUrlAuthozied){
    NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
    NSError *error;

    [fileCoordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {

        NSData *data = [NSData dataWithContentsOfURL:newURL];
        //Do something with data
        selectedDocumentToUpload = [[UploadDocumentObj alloc] initWithiCloudDocument:data];
        [self performSegueWithIdentifier:@"goToRename" sender:nil];

    }];
    [url stopAccessingSecurityScopedResource];
}else{
     //Error handling
    [Lib showErrorMessageWithTitle:@"Alert" message:@"E-Sign could not retrive the document!\nPlease try again." delegate:self]; …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios icloud uidocumentpickervc

10
推荐指数
2
解决办法
4695
查看次数

如何在iOS App Bundle中创建非本地化资源

我正在尝试在我的应用程序收到通知时播放自定义声音,作为Apple Docs的一部分,这应该通过以下方式完成:

You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle

我的问题是你如何创建一个非本地化的资源?将音频文件拖放到Xcode项目时会自动创建吗?是否在Info.plist中指定了?

我可以使用以下代码播放声音文件:

if let buttonBeep = self.setupAudioPlayerWithFile("0897", type:"aiff") {
    self.buttonBeep = buttonBeep
}

buttonBeep?.volume = 1.0
buttonBeep?.play()
Run Code Online (Sandbox Code Playgroud)

...

func setupAudioPlayerWithFile(file:NSString, type:NSString) -> AVAudioPlayer?  {
    let path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String)
    let url = NSURL.fileURLWithPath(path!)
    var audioPlayer:AVAudioPlayer?
    do {
        try audioPlayer = …
Run Code Online (Sandbox Code Playgroud)

audio xcode push-notification apple-push-notifications ios

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

conformsToProtocol不会使用自定义协议进行编译

我想检查一个UIViewController符合我自己创建的协议:

import UIKit

protocol myProtocol {
    func myfunc()
}

class vc : UIViewController {

}

extension vc : myProtocol {
    func myfunc() {
        //My implementation for this class
    }
}

//Not allowed
let result = vc.conformsToProtocol(myProtocol)

//Allowed
let appleResult = vc.conformsToProtocol(UITableViewDelegate)
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

Cannot convert value of type '(myprotocol).Protocol' (aka 'myprotocol.Protocol') to expected argument type 'Protocol'

操场

我究竟做错了什么?

protocols ios swift

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

在 Swift TDD 中模拟 NSBundle

是否可以模拟应用程序 NSBundle 以在 TDD 期间返回可预测的结果?

例如:

我想测试我的应用程序在文件未保存到 NSBundle 时是否进行处理:

//Method to test
func getProfileImage() -> UIImage {
    if let profileImagePath = getProfilePhotoPath() {
        UIImage(contentsOfFile: profileImagePath)
    }
    return UIImage(named: "defaultProfileImage")
}

private func getProfilePhotoPath() -> String? {
    return NSBundle.mainBundle().pathForResource("profileImage", ofType: "png")
}
Run Code Online (Sandbox Code Playgroud)

是否可以模拟 NSBundle.mainBundle() 为 pathForResource 返回 false ?

tdd unit-testing mocking ios swift

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

NSDate dateByAddingUnit强制选项 - nil不编译

所以我刚试了一下我认为简单的操作 - 给NSDate添加一天:

继这个答案也SO它提供了以下解决方案,而不是我想要什么(但具有相同的逻辑)不工作:

let twoDaysAgo = calendar.dateByAddingUnit(NSCalendarUnit.Day, value: -2, toDate: NSDate(), options: nil)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

"Could not find an overload for 'NSDate.init' that accepts the supplied arguments
Run Code Online (Sandbox Code Playgroud)

删除NSDate()参数后形成这个:

let d = NSDate()
let twoDaysAgo = calendar.dateByAddingUnit(NSCalendarUnit.Day, value: -2, toDate: d, options: nil)
Run Code Online (Sandbox Code Playgroud)

我现在得到一个不同的错误:

'Int' is not convertible to 'IntegerListeralConvertible'
Run Code Online (Sandbox Code Playgroud)

在搜索了各种出口之后,事实证明错误在最后的参数中options:nil- 现在必须传递参数.

为什么会这样?

NSHipster声明:

components(_:fromDateComponents:toDateComponents:options :):返回两个NSDateComponents实例之间的差异.该方法将使用未设置的任何组件的基值,因此至少为每个参数提供年份.options参数未使用; 传递nil/0.

虽然Apple没有明确说明论点不能为零

计算选项.有关可能的值,请参阅"日历选项".如果指定"wrap"选项(NSWrapCalendarComponents),则指定的组件会递增并在溢出时回绕到零/ 1,但不会导致更高的单位递增.当wrap选项为false时,单元中的溢出会进入更高的单位,如典型的添加.

这是一个XCode 7 beta错误吗?Swift 2中的新功能?

ios swift xcode7 swift2 xcode7-beta5

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

XCTAssertEqual 这个或那个

是否可以测试结果是否是两个选项之一?

例如:

let result = "apple" //Could be "apple" or "orange"
let expected1 = "apple"
let expected2 = "orange"

XCTAssertEqual(result, expected1 || expected2)
Run Code Online (Sandbox Code Playgroud)

ios xctest swift

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

迦太基错误:没有可用的二进制版本

在Cartfile中指定二进制文件的新版本时。迦太基无法下载/查找新版本并返回错误。

例如:

binary "<URL>" == 1.1.0(以前是binary "<URL>" == 1.0.0

错误:

No available version for binary "<URL>" satisfies the requirement: == 1.1.0

continuous-integration ios swift carthage

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