Tag: swift

通过Facebook Graph API获取个人资料图片返回“不支持的URL”

我正在开发iOS的应用程序,用户应该用Facebooklogin。 所以我想获得用户个人资料图片,但下面的代码是返回"unsupported URL" FBRequestConnection.startWithGraphPath("\(userID)/picture?type=large&access_token=207613839327374|BgKi3AePtvg1oDO8GTbWqqLE_SM", completionHandler: { (connection, result, error) -> Void in if (error? != nil){ NSLog("error = \(error)") }else{ println(result) } }) UPDATE 以下更改: FBRequestConnection.startWithGraphPath("\(userID)/picture?type=large", completionHandler: { (connection, result, error) -> Void in if (error? != nil){ NSLog("error = \(error)") }else{ println(result) } }) 正在返回: error = Error Domain=com.facebook.sdk Code=6 "Response is a non-text […]

我如何在iOS7上支持自定义大小的单元格?

随着iOS8的发布,我devise了我的表格视图,利用自定义单元格的单元格。 但是我需要我的桌子在iOS7中工作。 我怎么做? 有没有办法在运行时检查自定义单元格是否被支持,或者我可以在我的控制器中实现一些不会在iOS7中调用的表格委托方法? 如果我在iOS7中尝试使用自定义单元格的表格,则会在控制台上看到以下错误: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix […]

如何使用iOS 7的NSURLSession接受自签名的SSL证书

我有以下代码(快速实施): func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool { return protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust } func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { if challenge.protectionSpace.host == "myDomain" { let credentials = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust) challenge.sender.useCredential(credentials, forAuthenticationChallenge: challenge) } } challenge.sender.continueWithoutCredentialForAuthenticationChallenge(challenge) } 它在iOS 8.x中完美工作 , 但不起作用的iOS 7.x在iOS 7.x我有错误: NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813) 任何想法? […]

不能将主要的Swift类导入testing目标?

我正在testing我的iOS应用程序中的类。 我试图通过添加import Pickle到我的PickleTests.swifttesting文件的顶部,将我的应用程序中包含所有类的目标Pickle导入到我的testing目标PickleTests ,但是我不断收到错误。 我收到的错误是:“无法导入桥接头(桥接头的path)”(桥接头的path显示在错误,而不是括号)。 我已经尝试在我的Pickle目标的生成设置中的“定义模块”设置为“是”,但它仍然不起作用。 我也在构build设置中validation了它具有桥接头文件的正确path。 任何关于如何设置我的testing的想法? 我在Xcode 6.3.2上。 请让我知道如果你需要任何额外的信息。 在新标签中打开图片,看看它是否更大。

在Swift中每30分钟发送一次位置更新

我有位置服务的背景模式,并且每30分钟发送一次位置(经度和纬度)到服务器。 现在我在控制台上打印相同的内容。 它似乎工作了一段时间,但我想知道如何在这种情况下与NSTimer工作。 我应该从哪里调用它? import UIKit import CoreLocation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var window: UIWindow? var locationManager = CLLocationManager() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to […]

下一步/完成button使用Swift与textFieldShouldReturn

我有一个MainView,当注册button被按下时,添加一个子视图(signUpWindow)。 在我的signUpWindow子视图(SignUpWindowView.swift)中,我用一个函数设置每个字段,例如: func confirmPasswordText() { confirmPasswordTextField.frame=CGRectMake(50, 210, 410, 50) confirmPasswordTextField.placeholder=("Confirm Password") confirmPasswordTextField.textColor=textFieldFontColor confirmPasswordTextField.secureTextEntry=true confirmPasswordTextField.returnKeyType = .Next confirmPasswordTextField.clearButtonMode = .WhileEditing confirmPasswordTextField.tag=5 self.addSubview(confirmPasswordTextField) } 我有键盘移动signUpWindow上下时,它出现在MainView中消失。 SignUpWindowView实现了UITextFieldDelegate 我的问题是,我正试图configuration键盘上的下一步/完成button,并不确定哪个视图( MainView或SignUpWindowView )添加textFieldShouldReturn函数。 我已经尝试了两个,但是甚至不能得到一个println来testing,看看该函数是否被执行。 一旦我得到textFieldShouldReturn火,我相信我可以执行必要的代码来获得下一个/完成button来做我想做的,并将发布最终的解决scheme,包括下一个/完成function。 已更新包含SignUpWindowView.swift的缩写版本 import UIKit class SignUpWindowView: UIView,UITextFieldDelegate { let firstNameTextField:UITextField=UITextField() let lastNameTextField:UITextField=UITextField() override func drawRect(rect: CGRect){ func firstNameText(){ firstNameTextField.delegate=self firstNameTextField.frame=CGRectMake(50, 25, 200, 50) firstNameTextField.placeholder="First Name" firstNameTextField.returnKeyType = […]

iOS:'MyViewController'不符合协议'UITableViewDataSource'

我是IOS swift开发新手。 我曾经使用以前的Xcode 6 beta 。 我已经下载的Xcode 6.0.1 ,我不能得到这个工作Xcode Version: 6.0.1 当我尝试运行示例时,仍然收到“ MyViewController ”未确认协议“ UITableViewDataSource ”。 有人可以帮帮我吗? 我已经经历了这个网站上的其他问题,并添加了“ UITableViewDataSource ”所需的所有function; import UIKit import Foundation class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var array1:[String] = ["one","two","three","four"] var array2:[String] = ["IOS","Android","java","c++","Swift"] let sectionCount = 2 var myTableView:UITableView! // init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { // var rect […]

UIActivityViewController UIActivityViewControllerCompletionWithItemsHandler

项目清单 对于在iOS 8中运行的应用程序使用Swift,我需要为UIActivityViewController编写一个完成处理程序来捕获用户select的“共享”方法的结果。 这是迄今为止的代码片段。 我的问题是如何设置avc.completionWithItemsHandler ? 我相信这很简单,但我没有看到。 var activityItems = NSMutableArray() activityItems.addObject("Email or text for 'share' goes here") var avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil) avc.setValue("Subject for Email", forKey: "Subject") avc.completionWithItemsHandler = //Here is where I dont know what to do. self.navigationController?.presentViewController(avc, animated: true, completion: nil)

Swift中`关键字的含义?

我试图从parse.com实现一些代码,我注意到在void之后的关键字。 我难过这是什么? 第二行你看到了Void in PFUser.logInWithUsernameInBackground("myname", password:"mypass") { (user: PFUser?, error: NSError?) -> Void in if user != nil { // Do stuff after successful login. } else { // The login failed. Check error to see why. } } 文档没有logging这一点。 我知道in关键字用于for循环。 任何人确认?

UItesting用例不显示代码覆盖率

我有一些使用XCTestCase类写的testing,我想计算代码覆盖率。 对于常规testing,它在我的机器人中很好地显示,但对于UItesting总是0%。 最简单的testing: import XCTest class FAQUITests: XCTestCase { let app = XCUIApplication() override func setUp() { super.setUp() app.launch() } func openFaqView() { app.navigationBars["NavigationBar"].buttons["FAQ"].tap() } func testFaq() { openFaqView() app.tables.cells.elementBoundByIndex(0).tap() } } 这肯定应该显示一些testing覆盖,但事实并非如此。 我在我的bot代码覆盖范围内启用: 结果: 仍然是0%。 Xcode 7.2(7C68) 编辑:示例项目: https://Kettu@bitbucket.org/Kettu/so_34718699.git