com推送通知不发送

com推送通知不发送

本文介绍了Android的Parse.com推送通知不发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作接收,可以接收来自iOS设备和分析网站发送推送通知的Andr​​oid应用程序。

I have an Android app with a working receiver that can receive the push notification sent from iOS device and Parse website.

然而,在下列情况下不工作

However, the following cases are not working:


  • 从Android电子发送推送通知到Android

  • 从Android电子发送推送通知到iOS

由于Android应用程序可以收到推送通知,没有任何问题,我想一定有什么用发送推送通知我的逻辑/ code

Since the Android app can receive push notifications without any problems, I guess there must be something with my logic/code of sending the push notifications

在使用 parsePush.sendInBackground(SendCallback)方法发送推送通知,它会返回 ParseException的秒。因此,这意味着没有错误。

When sending push notifications using parsePush.sendInBackground(SendCallback) method, it returns no ParseExceptions. So it means no error.

不过,解析仪表盘不显示(在这种情况下无​​论是iOS或Android设备),这推送通知和目标目的地没有得到任何东西。

But the Parse Dashboard does not show this push notifications and the target destination (either iOS or Android device in this case) does not get anything.

在正常情况下,当一个推送通知是通过解析发送,它会显示在仪表盘推历史(的工作情况做了),但是当我尝试发送从Android设备推送,它只是不显示在仪表板和任何的推永远不会得到传递。

In the normal case, when a push notification is sent via Parse, it will show up as a push history in the Dashboard (the working case does that), but when I tried to send pushes from Android device, it just not show anything in the Dashboard and the pushes are never get delivered.

有问题的的Andr​​oid code:

The problematic Android code:

public void onShouldSendPushData(MessageClient messageClient, Message message, List<PushPair> pushPairs) {
        //TODO setup offline push notification
        Log.d(TAG, "Recipient not online. Should notify recipient using push");
        if (pushPairs.size() > 0 && !chatRecipient.isEmpty()) {
            PushPair pp = pushPairs.get(0);
            String pushPayload = pp.getPushPayload();

            ParsePush parsePush = new ParsePush();
            ParseQuery query = ParseInstallation.getQuery();
            ParseQuery userQuery = ParseUser.getQuery();
            userQuery.whereEqualTo("username", chatRecipient);
            query.whereMatchesQuery("user", userQuery);
            parsePush.setQuery(query);

            // JSON object for android push
            String alertString = getResources().getString(R.string.push_notification_msg);

            try {
                JSONObject data = new JSONObject();
                data.put("alert", String.format(alertString, chatRecipient));
                data.put("badge", "Increment");
                data.put("sound", "default");
                // pass the sender name as "title"
                data.put("title", ParseUser.getCurrentUser().getUsername());
                data.put("uri", "");
                data.put("SIN", pushPayload);

                parsePush.setData(data);
                parsePush.sendInBackground(new SendCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e == null) {
                            Log.i(TAG, String.format("Push notification to %s sent successfully", chatRecipient));
                        } else {
                            Log.e(TAG, String.format("Private chat push notification sending error: %s", e.getMessage()));
                        }
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

工作的iOS code:

The working iOS code:

- (void)message:(id<SINMessage>)message shouldSendPushNotifications:(NSArray *)pushPairs {
    // use parse to send notifications
    // send notifications
    NSLog(@"Recipient not online. Should notify recipient using push");
    if (pushPairs.count > 0 && userSelected != nil) {
        pushData = [[pushPairs objectAtIndex:0] pushData];
        pushPayload = [[pushPairs objectAtIndex:0] pushPayload];

        PFPush *push = [[PFPush alloc] init];
        PFQuery *query = [PFInstallation query];
        PFQuery *userQuery = [PFUser query];
        [userQuery whereKey:@"username" equalTo:userSelected];

        [query whereKey:@"user" matchesQuery:userQuery];
        [push setQuery:query];
        NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSString stringWithFormat:@"You have a new Message from %@", [PFUser currentUser].username], @"alert",
                              @"Increment", @"badge",
                              @"default", @"sound",
                              pushPayload, @"SIN",
                              nil];

        [push setData:data];
        [push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (succeeded) {
                NSLog(@"Push notification to %@ sent successfully.", userSelected);
            } else {
                NSLog(@"push notifications sending error: %@", error);
            }
        }];
    } else {
        NSLog(@"Error: No push pairs.");
    }

注意

我可以证实,code以上获取调用我想送推送通知各一次,并且不返回任何异常。我还可以确认推包装里面的数据不为空。

Note

I can confirm that the code above is getting called each time I want to send push notifications, and no exceptions are returned. I can also confirm that the data packaged inside the push is not null.

我不张贴接收机的code作为code的部分工作,应该什么都不做这个问题。

I'm not posting the receiver's code as that part of code is working and should do nothing with this issue.

iOS的code和Android code基本上都是一样的,为什么在Android中发送推送功能不工作?

The iOS code and Android code basically are the same, why the sending pushes function in Android not working?

我升级解析SDK 1.8.2来,其日志选项设置为详细和仍然无法找到,为什么推通知不会发送任何线索。

I upgraded Parse SDK to 1.8.2, with its Logging options set to VERBOSE and still can't find any clue why the Push notifications are not sent.

我甚至做了一个简单的项目了,只有登录解析示例项目,并发送短信的功能和它的发送消息功能仍无法正常工作。如此令人沮丧。

I even made a simple project out of the Parse example project with only Login and send message functions and its sending message function is still not working. So frustrating.

推荐答案

我已经找到了原因。

这里面的JSONURI字段中。

It is the "uri" field inside JSON.

只要这个字段包含(有或没有的内容),通知似乎被忽略了解析,但你会得到一个非错误回调。

As long as this field is included (with or without the content), notifications seemed being ignored by Parse, although you'll get a non-error callback.

如果您删除URI字段中输入您的JSON内,通知将趋于正常。

If you remove "uri" field inside your JSON, notifications will become normal.

我汇报这个bug来分析,他们已经开始解决这个问题。

I've reported this bug to Parse and they've started to solve it.

据从Parse.com的答复,这是一个预期的功能,因此具有URI字段中的通知将在服务器端被丢弃,因此它不会被发送。

According to the reply from Parse.com, this is an intended feature, so the notifications with "uri" field will be discarded on the server side, thus it will not be sent.

相关链接:

这篇关于Android的Parse.com推送通知不发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:59