gpt4 book ai didi

objective-c - Swift 和 ScriptingBridge.framework

转载 作者:可可西里 更新时间:2023-10-31 23:45:42 26 4
gpt4 key购买 nike

在我的 Swift 项目中,我需要通过 ScriptingBridge 框架与 iTunes 通信。根据 Apple 文档,我使用 sdef/Applications/iTunes.app | 创建了 iTunes.h 文件。 sdp -fh --basename iTunes,然后将 ScriptingBridge.framework 链接到项目并使用 #import "iTunes.h" 创建 AppName-Bridging-Header.h 文件。

但是当我尝试获取任何 iTunes 应用程序属性时,例如

var iTunesApp: iTunesApplication? = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") as? iTunesApplication
let currentTrack: iTunesTrack? = iTunesApp?.currentTrack

我收到类似这样的链接器错误

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_iTunesApplication", referenced from:
__TFC5NowP_14iTunesWorker21fetchCurrentTrackInfofS0_FT_T_ in iTunesWorker.o
__TFC5NowP_14iTunesWorkercfMS0_FT_S0_ in iTunesWorker.o
_get_field_types_iTunesWorker in iTunesWorker.o
"_OBJC_CLASS_$_iTunesTrack", referenced from:
__TFC5NowP_14iTunesWorker21fetchCurrentTrackInfofS0_FT_T_ in iTunesWorker.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我使用 Xcode 6 beta 4。有什么想法吗?

最佳答案

检查一下,它使用 Swift 并且可以正常工作(我测试过)

https://gist.github.com/bjhomer/fe8b3b05388b71ba0ab9

import ScriptingBridge

@objc protocol iTunesTrack {
optional var name: String {get}
optional var album: String {get}
}

@objc protocol iTunesApplication {
optional var soundVolume: Int {get}
optional var currentTrack: iTunesTrack? {get}
}

extension SBApplication : iTunesApplication {}

let app: iTunesApplication = SBApplication(bundleIdentifier: "com.apple.iTunes")

// Because these are all optional properties (to avoid providing an implementation), we have
// to use '!' to indicate we know the implementation exists.
let track: iTunesTrack? = app.currentTrack!
let album = track?.album!
let trackName = track?.name!


println("Current track: \(trackName) - \(album)")

关于objective-c - Swift 和 ScriptingBridge.framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25011600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com