gpt4 book ai didi

apple-push-notifications - registerForRemoteNotifications() 回调未被调用

转载 作者:行者123 更新时间:2023-12-01 02:06:27 25 4
gpt4 key购买 nike

有人问过这个问题(例如 herehere ),但似乎没有一个解决方案适用于我的设置。
我正在 iOS 9/Xcode7 (beta 5) 中开发一个应用程序。
我已经创建了一个明确的 App ID/bundle 标识符。
(应用 ID 由 Xcode 自动生成,但在 Developer Portal 中作为 Xcode iOS App ID com mycompanyname mayappname 监听)。
我在 Xcode 中配置了目标的“功能”以添加对推送通知的支持。
我已经在开发者门户中配置了我的 App ID 以支持推送通知:
我创建并下载了一个开发 APNs 证书,并安装在我的钥匙串(keychain)中(不确定这是否需要?我认为这个证书是为我的服务器准备的?但只是为了安全,以防在构建时需要它?)
我正在设备上从 Xcode 运行应用程序:iPhone 5s、iOS 9、4G 连接、Wi-Fi 已关闭(以防万一)。
我的应用程序未在设备的 Settings.app 的“通知”部分中列出,因此我无法在其中启用任何内容...
我像这样启动注册过程:

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?
) -> Bool
{
application.registerForRemoteNotifications()

return true
}
我已经实现了两个:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{

}
...和:
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)
{

}
并在两者上设置断点/日志,但都没有被调用。
会发生什么?
编辑:它现在可以工作,但前提是我调用 两个 registerForRemoteNotifications() registerUserNotificationSettings()发射时。
我的工作假设是我应该首先调用 registerForRemoteNotifications() ,并且在成功时(即 application(_:didRegisterForRemoteNotificationsWithDeviceToken) )我应该依次调用 registerUserNotificationSettings()指定通知的类型(并提示用户)。文档没有明确说明必须首先调用这两个函数中的哪一个;特别是 registerForRemoteNotifications() 的内联文档说:

[...] Call this method to initiate the registration process[...]


,这似乎表明它单独触发了整个事情。但是, programming guide有以下分步说明:
  1. Register the notification types your app supports using registerUserNotificationSettings:.
  2. Register to receive push notifications via APNs by calling your app’s registerForRemoteNotifications method.
  3. Store the device token returned to the app delegate by the server for a successful registration, or handle registration failuregracefully.
  4. Forward the device token to the app’s push provider.


更新(2015 年 1 月):
我转移到另一个项目,所以我没有跟进这个问题或找到一个明确的回应。仍在听任何有用的信息...

最佳答案

你很亲密。

您需要先调用registerForRemoteNotificationTypes:registerUserNotificationSettings: (iOS >=8)

然后打电话

registerForRemoteNotifications:

你有那个示例代码:
   // Register the supported interaction types.

UIUserNotificationType types = UIUserNotificationTypeBadge |

UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

UIUserNotificationSettings *mySettings =

[UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];



// Register for remote notifications.

[[UIApplication sharedApplication] registerForRemoteNotifications];

通过:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

关于apple-push-notifications - registerForRemoteNotifications() 回调未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32134225/

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