小编B R*_*Rad的帖子

Android GCM和多个令牌

我在GCM中使用GoogleCloudMessaging.getInstance(context)注册; 并将收到的令牌保存在设备上.然后将其发送到服务器,它与用户帐户相关联.如果我卸载我的应用程序而没有注销并再次安装并与其他用户一起登录,我会收到新令牌并将其发送到服务器.当推送发送给第一个用户时,我在第二个用户登录时看到它们.

为什么GCM会向我发送不同的令牌,我该如何处理?

android push-notification google-cloud-messaging

15
推荐指数
2
解决办法
1万
查看次数

连接耗尽后打开新连接.Google Cloud Messaging

我对Google Cloud Messaging有些陌生.我们已经使用了几个月,但最近我们收到了"连接耗尽"消息.当发生这种情况时,所有通

谷歌说:https://developer.android.com/google/gcm/ccs.html#response

收到CONNECTION_DRAINING消息时,应立即开始向另一个CCS连接发送消息,必要时打开新连接.但是,您应该保持原始连接处于打开状态并继续接收可能通过连接传递的消息(并确认它们)-CCS将在准备好时处理关闭时启动连接.

我的问题是

  1. 如果我手动打开一个新连接,如果我不关闭现有连接,它如何知道要使用哪个连接?
  2. 如果同时发送6条消息,如何阻止该方法打开6个连接?或者我对此感到困惑?
  3. 为什么连接耗尽?

我很惊讶这在他们的示例代码中尚未发挥作用.它似乎几乎是你需要的一切.代码中是否已经为我完成了,我很想念它?

我的代码中没有main方法,而是将servlet用作触发器.我的连接是这样开始的

@PostConstruct
    public void init() throws Exception{
        try {
            smackCcsClient.connect(Long.parseLong(env.getProperty("gcm.api")), env.getProperty("gcm.key"));
        }catch (IOException e ){
            e.printStackTrace();
        }catch(SmackException e){
            e.printStackTrace();
        }catch(XMPPException e){
            e.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

然而在此之后我再也没有碰过这个连接.我是否正在处理这个错误,是我应该更频繁地触摸的连接还是我需要跟踪的东西?

_______________________在问题之后加上__________________

我在其示例代码中添加了一个连接,以尝试重新初始化连接.它看起来像这样:

if ("CONNECTION_DRAINING".equals(controlType)) {
            connectionDraining = true;
            //Open new connection because old connection will be closing or is already closed.
            try {
                connect(Long.parseLong(env.getProperty("gcm.api")), env.getProperty("gcm.key"));
            } catch (XMPPException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SmackException e) { …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc google-cloud-messaging

8
推荐指数
1
解决办法
1243
查看次数

FatalErrorException:错误:在非对象上调用成员函数has()

我已经阅读了很多这方面的主题,我似乎无法找到解决问题的方法.

我觉得问题很明显,也许我刚刚盯着它看了太长时间.

错误是FatalErrorException:错误:调用成员函数has()在/vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php第198行中的非对象

它说,看错误线.

public function getDoctrine()
    {
        if (!$this->container->has('doctrine')) {
            throw new \LogicException('The DoctrineBundle is not registered in your application.');
        }

        return $this->container->get('doctrine');
    }
Run Code Online (Sandbox Code Playgroud)

这是我的代码......

这是调用DAO控制器的主控制器

public function clickThroughAction(request $request, $hash)
    {
        if (isset($hash)) {
            $dbController = $this->get('database_controller');
            print_r($dbController->getReferralIdByHash($hash));
            return $this->redirect($this->generateUrl('home'));
        } else {
            return 0;

        }
    }
Run Code Online (Sandbox Code Playgroud)

这是正在使用的服务.

services:
    database_controller:
        class:  Fuel\FormBundle\Controller\DatabaseController
Run Code Online (Sandbox Code Playgroud)

这是调用数据库的dao控制器.

public function getReferralIdByHash($hash)
    {
        $em = $this->getDoctrine()->getManager();
        $query = $em->createQuery(
            'Select u From FuelFormBundle:UserReferrals u WHERE u.user_hash = :hash'
        )->setParameter('hash', $hash);

        $referral = $query->getResult();

        if …
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony

7
推荐指数
1
解决办法
2万
查看次数

Set default value for entity type in Symfony2

I couldn't figure out how to make a default value for an entity type in symfony2. My code looked like this:

$rewardChoice = $this->createFormBuilder($reward)
    ->add('reward_name', 'entity', array(
        'class' => 'FuelFormBundle:Reward',
        'property' => 'reward_name',
        'data' => 2,
        'query_builder' => function(EntityRepository $er){
            return $er->createQueryBuilder('r')
                ->where('r.active = 1')
                ->groupBy('r.reward_id')
                ->orderBy('r.reward_name', 'DESC');

        },
    ))
    ->getForm();
Run Code Online (Sandbox Code Playgroud)

However you need to hand in the object you are working with to make it work. My answer is below.

I found a lot of different answers on this …

php types symfony

6
推荐指数
2
解决办法
1万
查看次数

复制演示时出错"在映射时无法定义序列项"

我在尝试重现Symfony提供的演示时遇到错误.你可以在这里找到它. http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes

当我在控制器中包含表单时,我可以让表单工作得很好但是当我将表单作为自己的类时,我最终会得到一个错误.

在映射500内部服务器错误 - ParseException时,您无法定义序列项

日志返回:

CRITICAL - 未捕获的PHP异常Symfony\Component\Yaml\Exception\ParseException:"在映射中无法定义序列项"在/vagrant/vendor/symfony/symfony/src/Symfony/Component/Yaml/Parser.php第81行

我似乎无法找到问题所在.

Task.php文件:

    <?php

namespace Acme\TaskBundle\Entity;

class Task
{
    protected $task;

    protected $dueDate;

    public function getTask()
    {
        return $this->task;
    }
    public function setTask($task)
    {
        $this->task = $task;
    }

    public function getDueDate()
    {
        return $this->dueDate;
    }
    public function setDueDate(\DateTime $dueDate = null)
    {
        $this->dueDate = $dueDate;
    }
}
Run Code Online (Sandbox Code Playgroud)

DefaultController.php:

<?php
namespace Acme\TaskBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\TaskBundle\Entity\Task;
use Symfony\Component\HttpFoundation\Request;
use Acme\TaskBundle\Form\Type\TaskType;

class DefaultController extends Controller
{
    public function newAction(Request $request)
    {
        // create …
Run Code Online (Sandbox Code Playgroud)

php forms symfony

5
推荐指数
1
解决办法
4199
查看次数

错误:在非对象上调用成员函数get()

我试图用Swift_Message发送邮件但是当我去发送它不会发送的数据时我得到一个错误

FatalErrorException:错误:在/vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php第252行中调用非对象上的成员函数get()

这是我正在使用的电子邮件控制器.

use Symfony\Component\Finder\Shell\Command;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;

class EmailController extends Controller{

    public function createMessage($subject, $from, $from_name, $to, $to_name, $body){
        // Create the message
        $message = \Swift_Message::newInstance()

            // Give the message a subject
            ->setSubject($subject)

            // Set the From address with an associative array
            ->setFrom(array($from => $from_name))

            // Set the To addresses with an associative array
            ->setTo(array($to => $to_name))

            // Give it a body
            ->setBody($body, 'text/html');

        return $message;
    }

    public function sendEmail($message, $urlAlias){

        $this->get('mailer')->send($message);

        return $this->redirect($this->generateUrl($urlAlias)); …
Run Code Online (Sandbox Code Playgroud)

php controller symfony

2
推荐指数
1
解决办法
9955
查看次数