我已经构建了一个类似于Snapchat的消息传递应用程序 - 一个用户可以发送另一个用户图片.我正在尝试向应用添加推送通知,以便当从UserA向UserB发送消息时,UserB会收到"来自UserA的新消息"的推送通知.
我一直在研究这几个小时,我觉得我很亲密.
我正在尝试使用Parse发送推送通知.我希望它的工作方式如下:当UserA向UserB发送消息时,还会向UserB发送一条推送通知,其中显示"来自UserA的新消息".我成功地使用Parse网站向使用该应用程序的设备发送推送通知,但是无法在应用程序内(当用户发送消息时)向接收用户的设备成功发送推送通知.
推送通知显然是成功发送的,因为我的Parse帐户显示了我发送的消息.但是,没有消息实际到达目标设备,推送通知列表显示每个推送通知的0个订阅者.
我可以点击其中一个来查看详细信息.
此外,我正在使用分发/生产供应配置文件和证书.
这是我在UserA向UserB发送消息后发送推送通知的代码 - message
对象是已上传到Parse的消息,messageRecipients是消息发送到的用户:
// Send Push Notification to recipients NSArray *messageRecipients = [message objectForKey:@"recipientIds"]; PFQuery *pushQuery = [PFInstallation query]; [pushQuery whereKey:@"owner" containedIn:messageRecipients]; PFPush *push = [[PFPush alloc] init]; [push setQuery:pushQuery]; [push setMessage:[NSString stringWithFormat: @"New Message from %@!", [PFUser currentUser].username]]; [push sendPushInBackground];
这是我的AppDelegate.m相关方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Parse setApplicationId:@"[This is where my app Id is]" clientKey:@"[This is where client Id is]"]; [self customizeUserInterface]; [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound]; return YES; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [PFPush storeDeviceToken:deviceToken]; [PFPush subscribeToChannelInBackground:@""]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Did fail to register for push, %@", error); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; }
我还在Parse.com论坛上提交了一篇文章:https://parse.com/questions/sending-a-push-notification-from-one-user-to-another-user
有什么东西我错过了或做错了吗?
编辑:我现在能够在我的Parse帐户中看到订阅者,但我实际上并没有在我的设备上收到推送通知.当我尝试从Parse网站发送推送通知测试时也是如此.