小编chi*_*arm的帖子

将@available与存储的属性一起使用

我有一个使用本地通知并支持iOS 10的应用程序.我正在尝试添加iOS 9支持,这需要我使用旧的位置通知API.我试图在我的iOS 10代码上使用@available和#available,我无法弄清楚如何将我的中心变量仅用于运行iOS 10的设备.

当我将目标从iOS 10设置为9时,我收到此变量的错误消息:"UNUserNotificationCenter仅适用于iOS 10.0或更高版本." 它建议我将"@available(iOS 10.0,*)"添加到我的整个班级,我不想这样做,因为这个类中的代码将用于iOS 9.我很感激有关如何限制我的任何建议中心属性到iOS 10.

class ViewController: UIViewController, UITextFieldDelegate {

  let center = UNUserNotificationCenter.current()
  ...
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift

17
推荐指数
4
解决办法
4849
查看次数

类型'NSObject'没有成员'复制'

我刚刚更新到Xcode 8,现在我收到了项目中的错误

类型'NSObject'没有成员'copy'.

在升级Xcode之前,我没有收到此错误.

注意:我还在使用Swift 2.3.我将UILabel子类化,以便我可以允许用户在长按上复制标签上的文本.以下是我的代码.该行发生错误:

if action == #selector(NSObject.copy(_:))
Run Code Online (Sandbox Code Playgroud)

这是完整的代码:

class MCCopyableLabel: UILabel {

  override init(frame: CGRect) {
    super.init(frame: frame)
    sharedInit()
  }

  required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
    sharedInit()
  }

  func sharedInit() {
    userInteractionEnabled = true
    addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(MCCopyableLabel.showMenu(_:))))
  }

  func showMenu(sender: AnyObject?) {
    becomeFirstResponder()
    let menu = UIMenuController.sharedMenuController()
    if !menu.menuVisible {
      menu.setTargetRect(bounds, inView: self)
      menu.setMenuVisible(true, animated: true)
    }
  }

  override func copy(sender: AnyObject?) {
    let board = UIPasteboard.generalPasteboard()
    board.string = text
    let menu = UIMenuController.sharedMenuController() …
Run Code Online (Sandbox Code Playgroud)

ios swift xcode8

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

iOS Catalyst Cocoapod 框架错误——签名需要开发团队

我正在更新我的 iOS 应用程序以在 Mac 上运行。选择 Mac 复选框后,我在尝试为 Mac 构建时在下面的屏幕截图中收到错误消息。它告诉我我需要为这个 Cocoapod 框架选择一个开发团队。但是,我可以在不选择开发团队的情况下构建到 iPhone 或 iPad。

我尝试选择一个使错误消失的开发团队,但是当我将应用程序二进制文件上传到 Apple 时,它​​被拒绝并显示错误:ITMS-90284:代码签名无效 - 可执行文件“Timestamp.app/Contents/Frameworks/BSImagePicker。 framework/Versions/A/Resources/BSImagePicker.bundle' 必须使用配置文件中包含的证书进行签名。

我想我是从 Apple 收到这个错误的,因为我为这个 Cocoapod 框架选择了一个开发团队。

有关如何处理 Catalyst 应用程序的此错误的任何建议?

Mac 构建错误

ios cocoapods swift mac-catalyst

5
推荐指数
2
解决办法
1206
查看次数

kCLLocationAccuracyBestForNavigation 与 kCLLocationAccuracyBest

我正在构建一个速度计应用程序,显示用户当前的行驶速度。我想尽可能显示最准确的速度,因此我想弄清楚我是否应该使用 kCLLocationAccuracyBestForNavigation 或 kCLLocationAccuracyBest。

根据 Apple 的文档,kCLLocationAccuracyBestForNavigation 使用尽可能高的精度并将其与额外的传感器数据相结合,而 kCLLocationAccuracyBest 使用最高级别的精度但没有提及传感器数据。有谁知道这个额外的传感器数据是什么以及它是否用于计算更准确的速度?

我从 CLLocation 对象获得速度。

  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    for location in locations {
      let speed = location.speed
      ...
    }
  }
Run Code Online (Sandbox Code Playgroud)

core-location ios

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

Firebase存储警告:不推荐使用downloadURL()':使用`StorageReference.downloadURLWithCompletion()

我刚刚将我的项目更新到最新版本的Firebase存储,现在我收到一条警告:不推荐使用downloadURL():使用StorageReference.downloadURLWithCompletion()获取当前的下载URL.

我查看了Firebase图片上传文档,但它仍然引用了downloadURL()现在已经过折旧的文件.在下面的代码中,我将图像的下载URL作为字符串.该代码可以工作,但现在要进行更新,因为它downloadURL()已经过折旧

uploadProfilePicTask.observe(.success) { snapshot in

  guard let profilePicStringURL = snapshot.metadata?.downloadURL()?.absoluteString else { return }
  ...
Run Code Online (Sandbox Code Playgroud)

这是我尝试更新的.我用新的代码尝试了下面的代码downloadURLWithCompletion() 但是snapshot.metadata?.storageReference?返回nil,所以我无法检索url String.有谁知道如何在downloadURLWithCompletion()下面适当使用新的?

uploadProfilePicTask.observe(.success) { snapshot in
  snapshot.metadata?.storageReference?.downloadURL { URL, error in
    if let urlString = URL?.absoluteString {
      // Do something
    } else {
      return
    }
  }
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-storage

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

更改发送消息栏的颜色 (JSQMessagesViewController)

我正在使用 JSQMessagesViewController 向我的应用程序添加聊天功能。我将采用深色主题,并将聊天设置为黑色,除了发送消息栏。我一直无法弄清楚如何改变它的颜色(见下面的截图)。有人可以告诉我如何更改发送消息栏的颜色吗?

谢谢!

聊天示例

ios swift jsqmessagesviewcontroller

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

限制textField中的字符和字符长度(_:shouldChangeCharactersInRange:replacementString :)

我的应用程序中有一个用户名textField,我想限制为24个字符,不允许"|" 用户名中的管道.

我可以使用下面的代码单独执行这些操作,但是我无法将这两者组合到textField(_:shouldChangeCharactersInRange:replacementString :)中.

此代码成功禁止"|" 在用户名字段中.

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

    if textField === usernameField {
      // Create an `NSCharacterSet` set
      let set = NSCharacterSet(charactersInString:"|")

      // At every character in this "set" contained in the string,
      // split the string up into components which exclude the characters
      // in this inverse set
      let components = string.componentsSeparatedByCharactersInSet(set)

      // Rejoin these components
      let filtered = components.joinWithSeparator("")

      // If the original string is equal to the …
Run Code Online (Sandbox Code Playgroud)

ios swift

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