我正在试着在我的iPhone 4s上运行Swift应用程序。它在模拟器上运行良好,我的朋友也可以在他的iPhone 4s上成功运行。我有iOS 8和官方发布的Xcode 6。
我试过了
重启Xcode, iPhone,电脑
清洁和重建
撤销并创建新的证书/供应配置文件
运行路径搜索路径是$(inherited) @executable_path/Frameworks
包含Swift代码的嵌入内容是“是”
代码签名身份是开发人员
下面是完整的错误
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/AppName.app/AppName
Reason: no suitable image found. Did find:
/private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/AppName.app/Frameworks/libswiftCore.dylib: mmap() error 1 at
address=0x008A1000, size=0x001A4000 segment=__TEXT in Segment::map() mapping
/private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/APPLICATION_NAME/Frameworks/libswiftCore.dylib
我认为苹果在试图引用Swift库libswiftCore.dylib时,已经在Swift应用程序崩溃下总结了它
引自技术问答QA1886:
Swift app crashes when trying to reference Swift library
libswiftCore.dylib.
Q: What can I do about the libswiftCore.dylib loading error in my
device's console that happens when I try to run my Swift language app?
A: To correct this problem, you will need to sign your app using code
signing certificates with the Subject Organizational Unit (OU) set to
your Team ID. All Enterprise and standard iOS developer certificates
that are created after iOS 8 was released have the new Team ID field
in the proper place to allow Swift language apps to run.
Usually this error appears in the device's console log with a message
similar to one of the following:
[....] [deny-mmap] mapped file has no team identifier and is not a platform binary:
/private/var/mobile/Containers/Bundle/Application/5D8FB2F7-1083-4564-94B2-0CB7DC75C9D1/YourAppNameHere.app/Frameworks/libswiftCore.dylib
Dyld Error Message:
Library not loaded: @rpath/libswiftCore.dylib
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000120021088
Triggered by Thread: 0
Referenced from: /private/var/mobile/Containers/Bundle/Application/C3DCD586-2A40-4C7C-AA2B-64EDAE8339E2/TestApp.app/TestApp
Reason: no suitable image found. Did find:
/private/var/mobile/Containers/Bundle/Application/C3DCD586-2A40-4C7C-AA2B-64EDAE8339E2/TestApp.app/Frameworks/libswiftCore.dylib: mmap() error 1 at address=0x1001D8000, size=0x00194000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/C3DCD586-2A40-4C7C-AA2B-64EDAE8339E2/TestApp.app/Frameworks/libswiftCore.dylib
Dyld Version: 353.5
The new certificates are needed when building an archive and packaging
your app. Even if you have one of the new certificates, just resigning
an existing swift app archive won’t work. If it was built with a
pre-iOS 8 certificate, you will need to build another archive.
Important: Please use caution if you need to revoke and setup up a new
Enterprise Distribution certificate. If you are an in-house Enterprise
developer you will need to be careful that you do not revoke a
distribution certificate that was used to sign an app any one of your
Enterprise employees is still using as any apps that were signed with
that enterprise distribution certificate will stop working
immediately. The above only applies to Enterprise Distribution
certificates. Development certs are safe to revoke for
enterprise/standard iOS developers.
正如AirSign人员所说,问题的根源在于内部证书的主题字段中缺少OU属性。
主题:UID=269J2W3P2L, CN=iPhone分布:公司名称,OU=269J2W3P2L, O=公司名称,C=FR
我有一个企业发展证书,创建一个新的解决了这个问题。
对于我来说,构建一个依赖于第三方Swift库(例如SQLite)的MacOS命令行Swift应用程序,上面的解决方案似乎都不起作用。有效的方法是直接将以下路径添加到构建设置中的Runpath搜索路径中:
/应用程序/ xcode /内容/ /开发/工具链/ XcodeDefault.xctoolchain / usr / lib /快速/ macosx /
这样做确实会在运行时给出一个警告,说Xcode已经找到了两个版本的libswiftCore——这是有道理的。除了没有包含这一行导致Xcode找不到任何版本的libswiftCore。
无论如何,这将为我做,即使它似乎不正确-我的应用程序只是一个实用工具,我不打算分发,至少它现在运行!
我们有一个unity项目,它创建了一个xcode项目,其中包括使用swift的库。
我们尝试了这个话题上的每一个合理的建议。
毫无效果。代码在新设备上运行良好,在iOS上崩溃<=12
看起来swift是如此的聪明,即使你将它设置为"ALWAYS_EMBED_SWIFT_LIBRAIES"="YES",它也不包括swift库。
真正为我们解决问题的是在项目中包含一个虚拟的swift文件。
该文件必须包含对分派、基础库的调用。
显然,这暗示了mighty-xcode强制包含库,但这次是真的。
下面是我们添加的虚拟文件,使其工作:
import Dispatch
import Foundation
class ForceSwiftInclusion {
init() {
// Force dispatch library.
DispatchQueue.main.async {
print("something")
}
// Force foundation library.
let uuid = UUID().uuidString
print("\(uuid)")
}
}
对于统一,也添加项目。AddBuildProperty(target, "SWIFT_VERSION", "Swift 5");到创建xcode项目的后期处理。
我也有同样的问题
有很多答案,但我的答案可能会帮助别人。
// MARK: -核心数据堆栈
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let mom = NSManagedObjectModel.mergedModel(from: [Bundle(for: Self.self)])!
let container = NSPersistentContainer(name: "Test", managedObjectModel: mom)
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()