实施Pusher APNs通知

时间:2017-01-05 21:18:02

标签: ios cordova notifications pusher

来自promising tutorialnickjf89后,我尝试在香草Cordova项目中实施推送通知。

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

" only"失败的是实际推送通知。 看看Push Notification控制台,我看到我的请求到达了我的cordova频道。 但是在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

1 个答案:

答案 0 :(得分:0)

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

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

相关问题