2017-01-05 300 views
0

繼此promising tutorialnickjf89我嘗試在vanilla Cordova項目中實現推送通知。實施推送APNs通知

到現在爲止,當我從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 

回答

0

好了,再一次,問題是椅子和鍵盤之間...... 我找到了修復,這是關係到上載推的的APN證書和my-app-name.entitlements其中APS環境設置上生產而不是發展。

推杆的所有固定和功能,偉大的新功能!