我正在尝试获取会话登录项列表,以查看当前应用程序是否已注册,但出现问题....
以下是代码的快照:
var loginItems : LSSharedFileListRef=LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems!.takeUnretainedValue(), nil)!.takeUnretainedValue()
var seed :UInt32 = 0
var theLoginItemsRef=loginItems as LSSharedFileListRef
var loginItemsArray=LSSharedFileListCopySnapshot(theLoginItemsRef, &seed).takeUnretainedValue()
for item in (loginItemsArray as NSArray){
var itemRef = item as LSSharedFileListItemRef
var url=LSSharedFileListItemCopyResolvedURL(itemRef,0,nil).takeUnretainedValue()
// do something with url
}
它编译,但在运行时它会因为向下转换(var itemRef = item为LSSharedFileListItemRef)并且崩溃而抱怨。 (loginItems获取__NSCFType的类型(?? !!?)是否重要?)
它给了我以下错误:
* thread #1: tid = 0x66fb, 0x000000010db218a6 libswiftCore.dylib`swift_dynamicCastUnknownClassUnconditional + 134, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
* frame #0: 0x000000010db218a6 libswiftCore.dylib`swift_dynamicCastUnknownClassUnconditional + 134
frame #1: 0x000000010ddb1bb4 $__lldb_expr65`top_level_code + 2996 at playground65.swift:20
frame #2: 0x000000010ddb1e61 $__lldb_expr65`main + 49 at <EXPR>:0
...
有什么建议吗?