ios - 获取 token 失败,错误: Error Domain=NSCocoaErrorDomain Code=3000 "no valid ' aps-environment' entitlement string found for application"

标签 ios notifications push-notification apple-push-notifications provisioning-profile

在这个问题上卡住了很长一段时间。尝试运行以下行:

[application registerForRemoteNotifications];

并得到错误

(via: - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
})

2015-04-03 16:06:42.753 TownHall[696:169453] Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x17426a1c0 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}

Tried some of the stuff with the following associated post http://stackoverflow.com/questions/10987102/how-to-fix-no-valid-aps-environment-entitlement-string-found-for-application but little luck. 

这包括: 1)重新创建配置文件 2) 重新创建 ID 并检查它是否匹配并启用推送 3)清理重建等 4) 创建新证书 5) 使用 Xcode > Preferences > Accounts > View Details 刷新(选择你的账户)

想知道是否有人对此有任何解决方案?

很高兴分享人们可能认为对解决此问题有用的任何其他信息。

非常感谢您的帮助!

最佳答案

转到 Capabilities 部分下的项目 Target,您会发现此错误发光。 XCode 可能会建议自动为您修复它。 enter image description here

您必须在您的项目中创建一个包含以下内容的两个权利(AppName_Debug.entitlements 和 AppName_Release.entitlements)文件: AppName_Debug.entitlements

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
      <dict>
        <key>aps-environment</key>
          <string>development</string>
      </dict>
</plist>

AppName_Release.entitlements

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
      <dict>
        <key>aps-environment</key>
          <string>production</string>
      </dict>
</plist>

将这两个文件添加到 Build Settings 的 Code Signing Entitlments 下适当的选项下。

enter image description here

关于ios - 获取 token 失败,错误: Error Domain=NSCocoaErrorDomain Code=3000 "no valid ' aps-environment' entitlement string found for application",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29440627/

相关文章:

ios - 一张带有 alpha 滞后 spritekit 的图像

ios - 当 UItableViewcell 高亮显示时,UITableViewcell 的 subview 消失,无论如何要修复它?

ios - 滤镜 slider 推荐 [iOS]

android - 如何在不显示通知的情况下更新未读计数

ios - iPhone 上工具栏图标的合适大小是多少

android - 更改android中的通知铃声

android - NotificationManager 启动空 Activity

iOS 10如何处理用户点击推送通知

android - fcm 推送通知在一加 6 手机中不起作用

firebase - 无法在 iOS 9.2 上接收 FCM 主题消息