如何closures自动手势以导航控制器返回视图?

所以我注意到,当用户在屏幕的左侧滑动(以任一方向)时,我的所有视图都会接收到手势返回(popup视图)( 这是iOS7中的新增function ) 我已经尝试了迄今为止无济于事closures使用: [self.navigationItem setHidesBackButton:YES]; 在NavigationController本身的init中(就像代理似乎正在使用那样)。

如何在iOS 7.1中使用NSURLSessiontestingHTTP请求和响应?

我想知道如何使用NSURLSession“unit testing”HTTP请求和响应。 现在,我的完成块代码在作为unit testing运行时不会被调用。 但是,当从AppDelegate (didFinishWithLaunchingOptions)中执行相同的代码时,将调用完成块中的代码。 正如在这个线程中所build议的, NSURLSessionDataTask dataTaskWithURL完成处理程序没有被调用 ,需要使用信号量和/或dispatch_group“确保主线程被阻塞,直到networking请求结束。 我的HTTP发布代码如下所示。 @interface LoginPost : NSObject – (void) post; @end @implementation LoginPost – (void) post { NSURLSessionConfiguration* conf = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession* session = [NSURLSession sessionWithConfiguration:conf delegate:nil delegateQueue:[NSOperationQueue mainQueue]]; NSURL* url = [NSURL URLWithString:@"http://www.example.com/login"]; NSString* params = @"username=test@xyz.com&password=test"; NSMutableRequest* request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request […]

如何找出坐标之间的距离?

我想让它显示两个CLLocation坐标之间的距离。 有没有一个复杂的math公式做到这一点? 如果没有一个公式你会怎么做?

重置iPhone应用程序的钥匙串

我想知道是否有一种方法来重置我的应用程序的钥匙串。 我想知道是否有任何东西存在 [NSUserDefaults resetStandardUserDefaults] 为钥匙串。 即使应用程序被删除,钥匙链也不会被重置。 到目前为止,我知道的唯一方法是从应用程序中逐一重置它们。

来电后AVplayer恢复

我正在使用AVPlayer进行音乐播放。 我的问题是,来电后,玩家将不会恢复。 来电时如何处理?

安全的内存对于Swift对象

我正在写一个快速的应用程序,需要处理内存中的私钥。 由于这些对象的敏感性,当对象被释放时,这些键需要被清除(也被写为全零),并且内存不能被分页到磁盘(通常使用mlock()完成)。 在Objective-C中,您可以提供一个自定义的CFAllocator对象,它允许您使用自己的函数来分配/释放/重新分配对象使用的内存。 所以一个解决scheme是在objective-c中实现一个“SecureData”对象,该对象使用自定义的CFAllocator(也在objective-c中)在内部创build一个NSMutableData对象。 然而,有没有办法让我提供我自己的自定义内存分配函数的纯Swift对象(例如,一个结构或[UInt8])? 还是有更好的,“适当”的方式来实现这样的快速安全的内存?

iOS NSAttributedString为HTML

我有一个NSAttributedstring(来自HTML),我为UITextView设置。 – (void)setHtml:(NSString *)html { NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding]; // Create the HTML string NSDictionary *importParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSError *error = nil; self.htmlString = [[NSAttributedString alloc] initWithData:htmlData options:importParams documentAttributes:NULL error:&error]; self.editorView.attributedText = self.htmlString; } 然后我让用户编辑他们想要的,然后我想再把它转换成HTML,所以我使用: – (NSString *)getHTML { NSDictionary *exportParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSData *htmlData = [self.editorView.attributedText dataFromRange:NSMakeRange(0, self.editorView.attributedText.length) documentAttributes:exportParams error:nil]; return […]

ALAssetsLibrary assetForURL:在iOS 8.1的“我的照片stream”中总是返回零

此代码在iOS 7中运行良好,但在iOS 8.1中,位于“我的照片stream”专辑中的所有资源都不在结果块内。 (failureBlock不叫。)普通的专辑和共享相册工作得很好。 我尝试从接受的答案: 尝试从assetForURL中分配__block ALAsset时出错:resultBlock: 也就是说,我持有一个对ALAssetsLibrary对象的引用,监听ALAssetsLibraryChangedNotification事件(这不是偶然发生的,但是哦)。我确定我的应用程序有权访问照片,我在无线上,我在我的tableView中看到了照片的缩略图。 只是当我尝试使用assetForURL:加载它们时assetForURL:它们总是零。 // example URL: assets-library://asset/asset.JPG?id=1ECB69B9-DC7A-45A7-B135-F43317D3412C&ext=JPG [self.library assetForURL:[NSURL URLWithString:url] resultBlock:^(ALAsset *asset) { NSLog(@"Asset: %@", asset); // nil 🙁 } failureBlock:^(NSError *error) { NSLog(@"Failure, wahhh!"); }]; 有没有人看到这个问题?

代码签名错误每当我尝试更换新的SceneKit应用程序中的股票文件

所以Xcode 8最近刚刚发布,我还不确定究竟是什么原因导致了这个问题(这可能只是Xcode的一个testing版本,或者我可能是在某种程度上做错了)。 现在的问题是,我正在尝试创build一个新的SceneKit应用程序,我正在搞乱.scn文件。 我在“hero.scnassets”里面创build了一个.scn文件,“hero.scn”,并且在hero.scnassets文件夹内以“heroTexture.png”的名字提供了一个.png文件。 这个项目在“GameViewController.swift”文件中通常由Xcode 8.0 beta 1提供的代码被编辑如下: 原始代码: … let scene = SCNScene(named: "art.scnassets/ship.scn")! … let ship = scene.rootNode.childNode(withName: "ship", recursively: true)! ship.run(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1))) 编辑的代码: … let scene = SCNScene(named: "hero.scnassets/hero.scn")! … let hero = scene.rootNode.childNode(withName: "hero", recursively: true)! hero.run(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1))) 收到的错误: […]

用Swift裁剪图像并放在中心位置

在Swift编程中,如何裁剪图像并将其放在中间位置? 这就是我迄今为止所做的…我已经成功地裁剪了图像,但是我想把它放在中心之后 ImgView.image = OrigImage var masklayer = CAShapeLayer() masklayer.frame = ImgView.frame masklayer.path = path.CGPath masklayer.fillColor = UIColor.whiteColor().CGColor masklayer.backgroundColor = UIColor.clearColor().CGColor ImgView.layer.mask = masklayer UIGraphicsBeginImageContext(ImgView.bounds.size); ImgView.layer.renderInContext(UIGraphicsGetCurrentContext()) var image = UIGraphicsGetImageFromCurrentImageContext() ImgView.image = image UIGraphicsEndImageContext(); 更新: let rect: CGRect = CGRectMake(path.bounds.minX, path.bounds.minY, path.bounds.width, path.bounds.height) // Create bitmap image from context using the rect let imageRef: CGImageRef […]