xcode UNUserNotificationCenter 链接错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40691774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UNUserNotificationCenter link error
提问by Patrick Bodet
I have an Xcode project, Xcode 8.1 (8B62) with two targets, one for the paid version of the application and the other for the free version. They both manage remotes push notifications. Since I made the changes for iOS 10 with the new framework UNUserNotificationCenter.framwork, everything is fine for the first target and I have a link error for the second. It worked well under iOS 9 with the old methods. What I did for both targets:
我有一个 Xcode 项目,Xcode 8.1 (8B62) 有两个目标,一个用于应用程序的付费版本,另一个用于免费版本。他们都管理远程推送通知。由于我使用新框架 UNUserNotificationCenter.framework 对 iOS 10 进行了更改,因此第一个目标一切正常,第二个目标出现链接错误。它在 iOS 9 下使用旧方法运行良好。我为两个目标做了什么:
- Capabilities: Enabled Push Notifications (Entitlements are properly updated)
- In AppDelegate.h: #import
- In AppDelegate.m: Updated the code with the new methods
- 功能:启用推送通知(权利已正确更新)
- 在 AppDelegate.h 中:#import
- 在 AppDelegate.m 中:使用新方法更新了代码
It's the same code for both targets.
两个目标的代码相同。
Unfortunately, for the second target, I have the following error:
不幸的是,对于第二个目标,我有以下错误:
Undefined symbols for architecture arm64: ??"_OBJC_CLASS _ $ _ UNUserNotificationCenter", referenced from: ??????Objc-class-ref in AppDelegate.o Ld: symbol (s) not found for architecture Clang: error: linker command failed with exit code 1 (use -v to see invocation)
架构 arm64 的未定义符号:??"_OBJC_CLASS _ $ _ UNUserNotificationCenter",引用自: ??????Objc-class-ref in AppDelegate.o Ld:找不到架构 Clang 的符号:错误:链接器命令失败,退出代码 1(使用 -v 查看调用)
I have done several times clean and clean build target folder, re-start Xcode, re-start the computer but nothing is done.
我已经做了几次清理和清理构建目标文件夹,重新启动Xcode,重新启动计算机但什么也没做。
Nothing found in the different forums ...
在不同的论坛中找不到任何内容...
Help would be welcome. Thank you in advance.
欢迎提供帮助。先感谢您。
回答by shallowThought
You are not linking to the UserNotifications.framework
.
您没有链接到UserNotifications.framework
.
- Select your target
- Show its "Build Phases"
- Assure
UserNotifications.framework
exists in "Link Binary With Libraries"
- 选择你的目标
- 显示其“构建阶段”
- 确保
UserNotifications.framework
存在于“链接二进制与库”中
If it does not:
如果没有:
- Click "+" button and add it
- 单击“+”按钮并添加它
回答by auspicious99
I had almost exactly the same problem, with two targets, one for the free version, one for the paid version.
我遇到了几乎完全相同的问题,有两个目标,一个是免费版本,一个是付费版本。
I strongly suspect that the difference was that with one target, "Enable modules" was YES (this was the target for the free version, where I was doing an @import for Admob), whereas with the other target, "Enable modules" was NO. Like magic, I didn't have to add UserNotifications.framework in "Link Binary with Libraries" in Build Phases for the target where "Enable modules" was YES. However, for the target where "Enable modules" was NO, I got
我强烈怀疑不同之处在于,对于一个目标,“启用模块”是“是”(这是免费版本的目标,我正在为 Admob 执行 @import),而对于另一个目标,“启用模块”是不。就像魔术一样,对于“启用模块”为“是”的目标,我不必在构建阶段的“链接二进制与库”中添加 UserNotifications.framework。但是,对于“启用模块”为否的目标,我得到了
Undefined symbols for architecture arm64: "_OBJC_CLASS _ $ _ UNUserNotificationCenter
and it went away by manually adding UserNotifications.framework to "Link Binary with Libraries".
它通过手动将 UserNotifications.framework 添加到“Link Binary with Libraries”而消失了。
So maybe the rule is, this needs to be done if and only if modules are not enabled.
所以也许规则是,当且仅当模块未启用时才需要这样做。
回答by Munahil
Make sure UserNotifications.framework
exists in your Target > General > Linked Frameworks and Libraries
确保UserNotifications.framework
存在于您的Target > General > Linked Frameworks and Libraries