【问题标题】:Implementing Pusher APNs Notification实现 Pusher APNs 通知
【发布时间】:2017-05-20 13:49:39
【问题描述】:

按照nickjf89 中的promising tutorial,我尝试在一个普通的 Cordova 项目中实现推送通知。

到目前为止,我能够与套接字通信,当我从 Pusher 控制台推送数据时,一切正常,因此我排除了 Pusher API 上的任何错误配置。

“唯一”失败的是实际的推送通知。 查看推送通知控制台,我看到我的请求到达了我的科尔多瓦频道。 但是在 xCode 控制台中,我没有看到来自NSLog(@"Received remote notification: %@", userInfo); 的预期日志

我怀疑我的AppDelegate.m 有问题,如下所示。

#import "AppDelegate.h"
#import "MainViewController.h"

@import UserNotifications;
#import <PusherSwift/PusherSwift-Swift.h>

@interface AppDelegate ()
@property (nonatomic, retain, readwrite) Pusher *pusher;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.viewController = [[MainViewController alloc] init];

    self.pusher = [[Pusher alloc] initWithKey:@"here_i_put_my_pusher_app_key"];

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        // Enable or disable features based on authorisation.
    }];

    [application registerForRemoteNotifications];

    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Registered for remote notifications; received device token");
    [[[self pusher] nativePusher] registerWithDeviceToken:deviceToken];
    [[[self pusher] nativePusher] subscribeWithInterestName:@"cordova"];
    NSLog(@"Seeems token stuff works");
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSLog(@"Received remote notification: %@", userInfo);
}

@end

【问题讨论】:

    标签: ios cordova notifications pusher


    【解决方案1】:

    好吧,问题又出在椅子和键盘之间…… 我找到了修复,它与在 Pusher 上上传的 APNs 证书和 my-app-name.entitlements 相关,其中 APS 环境设置为生产环境而不是开发环境。

    Pusher 的所有固定且功能强大的新功能!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 2014-03-23
      • 2012-09-04
      • 2016-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多