我正在尝试让 Bluemix Cordova Hello World 示例与 IBM PushNotifications Service 配合使用。 我已经安装了科尔多瓦插件,如果我运行科尔多瓦插件列表,我会看到:
ibm-mfp-core 1.0.10 "MFPCore"
ibm-mfp-push 1.0.12 "MFPPush"
我的索引.js初始化代码如下所示:
onDeviceReady: function() {
BMSClient.initialize(app.route, app.guid);
BMSClient.registerAuthenticationListener("MyRealm", customAuthenticationListener);
// alert("******** ABOUT TO CALL MFPPush.registerDevice **************");
// MFPPush.registerDevice(iosPushSettings, pushSuccess, pushFailure);
MFPPush.registerDevice({}, pushSuccess, pushFailure);
我确实有 MAS 自定义身份验证服务正在运行和工作。
我正在通过Xcode在连接的iPad上运行代码。 我在插件 swift 文件中添加了一些 debugPrint 语句,并在 Xcode 控制台中看到以下消息:
"Inside Register Device!!!!!!!"
"Inside registerNotificationsCallback"
"Settings Parameter is not null"
"settings.count == 0"
"about to set notificationSettings"
"About to registerForRemoteNotifications"
"Called registerForRemoteNotifications"
我不是 swift 或 iOS 开发人员,所以我对调试和使用 iOS 应用程序一无所知。 我尝试在AppDelegate.m
文件中设置断点,似乎代码在didRegisterForRemoteNotificationsWithDeviceToken
中命中断点,我认为正在设置令牌值。 但是,我从未看到我的debugPrint代码在里面的CDVMFPPush.swift
文件中被触发
func didRegisterForRemoteNotifications(deviceToken: NSData) {
debugPrint("Inside didRegisterForRemoteNotifications")
或内部
func didFailToRegisterForRemoteNotifications(error: NSError) {
debugPrint("Inside didFailToRegisterForRemoteNotifications")
据我所知,我已经设置了 APNS 证书和配置配置文件,并且我已经将我的 sandboxAPNS.p12
文件上传到我的 Bluemix 推送服务中,没有任何错误。
在 Bluemix 推送仪表板上,如果我尝试向所有设备发送推送通知,则会收到以下错误:
Internal server error. No devices found
我还看到在 XCode 中我的应用程序的功能选项卡中启用了推送通知。
我正在尝试确定为什么我从未看到didRegister
或didFailToRegister
的 debugPrint 语句,以及为什么 Bluemix 看不到我的设备。 感谢您对如何调试的任何建议,并再次为我对 swift 和 XCode 的无知表示歉意。
JT
好的,我让推送通知工作。 事实证明,我需要根据文档和 Git 自述文件修改 AppDelegate.m 文件:
// Register device token with Bluemix Push Notification Service
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
[[CDVMFPPush sharedInstance] didRegisterForRemoteNotifications:deviceToken];
}
// Handle error when failed to register device token with APNs
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
[[CDVMFPPush sharedInstance] didFailToRegisterForRemoteNotifications:error];
}
// Handle receiving a remote notification
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo];
}