小编use*_*367的帖子

如何识别所有4个方向的滑动

我需要使用滑动来识别向下然后向右滑动手势.但是在快速的UISwipeGestureRecognizer上预先确定了正确的方向..而且我不知道如何使用其他方向.

direction swipe ios uiswipegesturerecognizer swift

123
推荐指数
7
解决办法
10万
查看次数

如何使用Swift获取当前语言代码?

我想在我用Swift编写的应用程序中获取设备的语言代码(en,es ...).怎么能得到这个?

我正在尝试这个:

  var preferredLanguages : NSLocale!
  let pre = preferredLanguages.displayNameForKey(NSLocaleIdentifier, value: preferredLanguages)
Run Code Online (Sandbox Code Playgroud)

但这会返回零.

谢谢!

nslocale swift

108
推荐指数
14
解决办法
9万
查看次数

如何使用openURL在Swift中拨打电话?

我已经将用于打电话的代码从Objective-C转换为Swift,但在Objective-C中,我们可以设置我们想要打开的URL类型(例如电话,短信,网络),如下所示:

@"tel:xx"
@"mailto:info@example.es"
@"http://stackoverflow.com"
@"sms:768number"
Run Code Online (Sandbox Code Playgroud)

Swift中的代码是:

UIApplication.sharedApplication().openURL(NSURL(string : "9809088798")
Run Code Online (Sandbox Code Playgroud)

我读过没有发布任何方案参数tel:,但我不知道Swift是否可以检测该字符串是用于打电话,发送电子邮件还是打开网站.或者我可以写:

(string : "tel//:9809088798")
Run Code Online (Sandbox Code Playgroud)

nsurl openurl swift xcode6

39
推荐指数
7
解决办法
5万
查看次数

如何使用healthkit解决此错误?

我在我的ios Swift应用程序中添加了healthkit的代码,但是我收到了错误...

 /* Ask for permission to access the health store */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

if HKHealthStore.isHealthDataAvailable(){

  healthStore.requestAuthorizationToShareTypes(typesToShare,
    readTypes: typesToRead,
    completion: {(succeeded: Bool, error: NSError!) in

      if succeeded && error == nil{
        println("Successfully received authorization")
      } else {
        if let theError = error{
          println("Error occurred = \(theError)")
        }
      }

    })

} else {
  println("Health data is not available")
}

}
Run Code Online (Sandbox Code Playgroud)

发生错误=错误域= com.apple.healthkit代码= 4"缺少com.apple.developer.healthkit权利." UserInfo = 0x7fa748534b00 {NSLocalizedDescription =缺少com.apple.developer.healthkit权利.}

怎么解决这个?

谢谢!

swift xcode6 ios8 healthkit

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