gpt4 book ai didi

ios - 观看扩展 NSBundle URLForResource 始终为零

转载 作者:行者123 更新时间:2023-11-29 01:08:47 26 4
gpt4 key购买 nike

在我的应用程序中,我使用带有资源目标的静态库,我已将资源目标连接到 Build Phases -> Copy Bundle Resources 并且我像这样获取库资源:

 NSUrl *resourcesUrl = [[NSBundle mainBundle] URLForResource:@"MySDKResources" withExtension:@"bundle"]
NSBundle *bundle = [NSBundle bundleWithURL:resourcesUrl];
NSString *path = [bundle pathForResource:filename ofType:fileExtension];

使用 watch 扩展,当应用程序收到 func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) 委托(delegate)时,我使用相同的代码,但这次

  • resourcesUrl 在不同的文件夹中,我在 finder 上找不到
  • 捆绑为零
  • 路径显然是nil
  • didReceiveMessage 委托(delegate)不在主线程上调用此代码(所以我在主线程上调度)

在同一 session 中,当其中一个应用程序类调用此代码文件路径时返回正常,但当 watch 扩展委托(delegate)调用相同代码时返回 nil

我尝试将静态库添加到 Target DependenciesCompile Sources并将资源目标添加到 Copy Bundle Resources 但我得到 No such file or directory 错误

最佳答案

好吧,事实证明,当您运行 watch 模拟器时,它会杀死 iPhone 模拟器上的应用程序(但不会使其崩溃),因此看起来应用程序正在运行,但实际上您无法实例化 bundle 或任何其他应用程序资源。 this blog post解释如何在调试时一起运行应用程序和监视应用程序。

TL;DR :

while running code on simulator on Xcode menu bar select Debug -> Attach to Process -> select the process of your iOS app from the list (It'll probably be under Likely Targets)

关于ios - 观看扩展 NSBundle URLForResource 始终为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36007178/

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