2016-05-20 13 views
1

でプッシュ通知を送信できません。ビルドターゲットは9.0です。は、私がiOS用PubNub SDKを使用して私のアプリにプッシュ通知を実装していますPubNub SDK

私はチュートリアルhere以下だけど、私はそれを動作させることはできませんし、私は私が概念を理解するためにいくつかのより多くの情報が必要と感じ。私はこれまで何をやったかを見てみましょう:didFinishLaunchingWithOptions機能で

AppDelegate.m

@interface AppDelegate() 

@property (nonatomic) PubNub *client; 

@end 

を、私はプッシュ通知を設定するには、このコードを実行します。

/* push notifications */ 
UIUserNotificationType types = UIUserNotificationTypeBadge | 
UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 

UIUserNotificationSettings *mySettings = 
[UIUserNotificationSettings settingsForTypes:types categories:nil]; 

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 
[[UIApplication sharedApplication] registerForRemoteNotifications]; 

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    NSLog(@"deviceToken: %@", deviceToken); 
    [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"DeviceToken"]; 
} 

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { 
    NSLog(@"%s with error: %@", __PRETTY_FUNCTION__, error); 
} 

このようなチュートリアルポストコードは、これは、デリゲートまたは他のViewControllersに行くことになっている?:

PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo" 
                   subscribeKey:@"demo"]; 
self.client = [PubNub clientWithConfiguration:configuration]; 
[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"] 
        withDevicePushToken:self.devicePushToken 
          andCompletion:^(PNAcknowledgmentStatus *status) { 

// Check whether request successfully completed or not. 
if (!status.isError) { 

    // Handle successful push notification enabling on passed channels. 
} 
// Request processing failed. 
else { 

    // Handle modification error. Check 'category' property to find out possible issue because 
    // of which request did fail. 
    // 
    // Request can be resent using: [status retry]; 
} 
}]; 

ViewController.m

@interface MessagingViewController() 

@property (nonatomic) PubNub *client; 
@property (nonatomic, strong) NSData *devicePushToken; 

@end 

-(void)viewDidLoad { 
    NSData *deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"]; 
if (deviceToken) 
{ 
    self.devicePushToken = deviceToken; 
    PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:publishKey 
                    subscribeKey:subscribeKey]; 
    self.client = [PubNub clientWithConfiguration:configuration]; 
    [self.client addPushNotificationsOnChannels:@[self.senderId] 
          withDevicePushToken:self.devicePushToken 
            andCompletion:^(PNAcknowledgmentStatus *status) { 

             // Check whether request successfully completed or not. 
             if (!status.isError) { 

              // Handle successful push notification enabling on passed channels. 
             } 
             // Request processing failed. 
             else { 

              // Handle modification error. Check 'category' property to find out possible issue because 
              // of which request did fail. 
              // 
              // Request can be resent using: [status retry]; 
             } 
            }]; 
} 
} 

コード私は通知を送信するために使用しています:

  /* send push notifications */ 
     [self.client publish:nil toChannel:self.senderId mobilePushPayload: @{@"aps": @{@"message":message}} 
       withCompletion:^(PNPublishStatus *status) { 

        // Check whether request successfully completed or not. 
        // if (status.isError) // Handle modification error. 
        // Check 'category' property to find out possible issue because 
        // of which request did fail. Request can be resent using: [status retry]; 
       }]; 

誰かが説明してくれ概要やコードの異なる部分のようなものを与えることができます所属し、何が必要ですか?

答えて

0

良い一日エリック、

すべてのコードがmobilePushPayloadパラメータに渡された辞書を除いて有効です。合格した辞書はApple Push Notificationsの場合にはspecificationと記載されています。 APNSペイロードにはメッセージキーはありませんが、少なくともそれのための警告と文字列値があるはずです。あなたが公開したい場合は

ので、あなたはこのような何かを試してみてください:

[self.client publish:nil toChannel:self.senderId mobilePushPayload: @{@"aps": @{@"alert":message}} 
 
     withCompletion:^(PNPublishStatus *status) { 
 

 
    // Check whether request successfully completed or not. 
 
    // if (status.isError) // Handle modification error. 
 
    // Check 'category' property to find out possible issue because 
 
    // of which request did fail. Request can be resent using: [status retry]; 
 
}];

敬具、
セルゲイ

私が見
+0

、ありがとう!また、app delegate内でaddPushNotificationsOnChannels呼び出しを行う必要がありますか? – Erik

+0

@Erikこのメソッドは、デバイスプッシュトークンを取得するたびに呼び出される必要があります。アプリケーションの代理人だけがこれに直接応答するので、そこに行うことをお勧めします。 –

+0

私は理解しています。だから私は、特定のユーザーにプッシュ通知を送信する場合、私は、例えば、ユーザーのIDと同等のIDを持つチャネルに送信することができますか?これらのチャンネルは通知グループの一種ですか? withDevicePushToken:andCompletion: 'メソッドあなたが特定のユーザーに通知を送信する場合 – Erik

関連する問題