ios – 如何在Watch OS 2中引用不支持的框架

ios – 如何在Watch OS 2中引用不支持的框架,第1张

概述我更新了我的应用程序到最新的 swift 2.0语法.在这样做时,我的watchkit应用程序已经破损.问题是watchkit应用程序引用引用框架AVFoundation的类. WatchOS2显然现在不再支持一些标准框架: Support for network-based operations includes the following technologies: WatchKit exte 我更新了我的应用程序到最新的 swift 2.0语法.在这样做时,我的watchkit应用程序已经破损.问题是watchkit应用程序引用引用框架AVFoundation的类. WatchOS2显然现在不再支持一些标准框架:

Support for network-based operations includes the following technologIEs:

WatchKit extensions can access the network directly through an
NSURLSession object. WatchKit extensions have full access to the
NSURLSession capabilitIEs,including the ability to download files in
the background. For information on how to use this class,see URL
Loading System Programming GuIDe. The Watch Connectivity framework
supports bIDirectional communication between your Watch app and iOS
app. Use this framework to coordinate activitIEs between the two apps.
See Communicating with Your Companion iOS App.

Available System Technologies for WatchKit

所以现在我无法编译手表套件代码为“没有这样的模块发现”是一个错误消息,当试图使用AVFoundation框架.我如何解决这个问题,并在我的苹果手表应用程序中继续引用该类和框架.我应该在手机和手表之间传输数据吗?有没有办法将框架链接到扩展名?

我正在尝试做的是以下,在我的InterfaceController中:

overrIDe func willActivate() {    super.willActivate()    let defaultsShared = NSUserDefaults(suitename: "somesharedappgroup")    let defaults = NSUserDefaults.standardUserDefaults()     if let barcodeString = defaultsShared!.objectForKey("barcode") as? String {        if let barcodeContent = RSUnifIEdCodeGenerator.shared.generateCode(barcodeString,machineReadableCodeObjectType: AVMetadataObjectTypeCode39Code) {            barcode.setimage(barcodeContent)            label.setText("ID: \(barcodeString)")        } else {            label.setText("Please setup extensions in the settings of SHPID.")            barcode.setimage(nil)        }    } else {        label.setText("Please setup extensions in the settings of SHPID.")        barcode.setimage(nil)    }}

RSUnifIEdCodeGenerator是一个使用AVFoundation从字符串生成条形码图像的类.此外,生成器的类型是AVObject:AVMetadataObjectTypeCode39Code.这个解决方案在第一个WatchOS中运行良好,但现在在 *** 作系统2中仍然存在破坏.我看到WatchConnectivity可能是一个解决方案,并且只是让我从手机本身传递条形码,但这将需要我停止支持iOS 8.什么是最好的解决方案,如果有的话,在WatchOS 2中使用AVFoundation.如果我不能这样做,我还应该怎么去把这个图像从手机传递到手表.谢谢.

解决方法 这是一个关于如何为您的应用程序使用WatchConnectivity的示例.

请不要这个例子是粗糙的,不会处理错误.会议管理也应该注意稳定的产品.

iPhone AppDelegate

import UIKitimport WatchConnectivityimport AVFoundationimport RSbarcodes@UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate,WCSessionDelegate {  var window: UIWindow?  func application(application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {    // OverrIDe point for customization after application launch.    if WCSession.isSupported() {      let session = WCSession.defaultSession()      session.delegate = self      session.activateSession()    }    return true  }  // On Watch sends the message.  // Will not reply as we will push a data message with image.  func session(session: WCSession,dIDReceiveMessage message: [String : AnyObject]) {    if "generatebarcode" == message["ID"] as! String {      let code = message["code"] as! String      let barcodeImage = RSUnifIEdCodeGenerator.shared.generateCode(code,machineReadableCodeObjectType: AVMetadataObjectTypeCode39Code)!      if WCSession.isSupported() {        let session = WCSession.defaultSession()        session.delegate = self        session.activateSession()        session.sendMessageData(UIImagePNGRepresentation(barcodeImage)!,replyHandler: nil,errorHandler: nil)      }    }  }}

观看InterfaceController

import WatchKitimport Foundationimport WatchConnectivityclass InterfaceController: WKInterfaceController,WCSessionDelegate {  @IBOutlet var barcodeImage: WKInterfaceImage!  overrIDe func willActivate() {    super.willActivate()    if WCSession.isSupported() {      let session = WCSession.defaultSession()      session.delegate = self      session.activateSession()      // Send a message requesting a barcode image      session.sendMessage(        ["ID": "generatebarcode","code": "2166529V"],// Do not handle response,iPhone will push a data message        errorHandler: nil)    }  }  // On iPhone pushes a data message  func session(session: WCSession,dIDReceiveMessageData messageData: NSData) {    barcodeImage.setimage(UIImage(data: messageData))  }}
总结

以上是内存溢出为你收集整理的ios – 如何在Watch OS 2中引用不支持的框架全部内容,希望文章能够帮你解决ios – 如何在Watch OS 2中引用不支持的框架所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1097208.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存