でプッシュ通知を送信できません。ビルドターゲットは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];
}];
誰かが説明してくれ概要やコードの異なる部分のようなものを与えることができます所属し、何が必要ですか?
、ありがとう!また、app delegate内でaddPushNotificationsOnChannels呼び出しを行う必要がありますか? – Erik
@Erikこのメソッドは、デバイスプッシュトークンを取得するたびに呼び出される必要があります。アプリケーションの代理人だけがこれに直接応答するので、そこに行うことをお勧めします。 –
私は理解しています。だから私は、特定のユーザーにプッシュ通知を送信する場合、私は、例えば、ユーザーのIDと同等のIDを持つチャネルに送信することができますか?これらのチャンネルは通知グループの一種ですか? withDevicePushToken:andCompletion: 'メソッドあなたが特定のユーザーに通知を送信する場合 – Erik