检查是否存在财产(Check if property exists)

是否有可能检查是否存在使用魔术设置器设置的属性?

class Test
{
    private $vars;

    public function __set($key, $value) {
        $this->vars[$key] = $value;
    }

    public function &__get($key)
    {
        return $this->vars[$key];
    }
}

$test = new Test;

$test->myvar = 'yay!';

if (magic_isset($test->myvar)) {
}

或者是不可能的,我只需要在我的班级设置另一个功能?


Is it possible to check if a property exists which are set using magic setter?

class Test
{
    private $vars;

    public function __set($key, $value) {
        $this->vars[$key] = $value;
    }

    public function &__get($key)
    {
        return $this->vars[$key];
    }
}

$test = new Test;

$test->myvar = 'yay!';

if (magic_isset($test->myvar)) {
}

Or isn't it possible and I just need to setup another function in my class?


原文:https://stackoverflow.com/questions/8763357
2024-02-09 15:02

满意答案

要求很简单。

您需要从每个客户端生成gcm令牌。

客户端A安装您的应用程序,并在启动/登录时(无论它适合您的业务逻辑),您将尝试生成此gcm令牌(让我们说10000是生成的令牌)。 并且您需要将此令牌发送到您的服务器以存储以便在将来的通信中使用它。 当你想与这个客户端A通信时,你需要告诉gcm服务器,

Hey Gcm server, send mobile with gcm token 10000 the following message "Event time updated"

因此,如果客户端b安装,它将生成其gcm令牌并以相同方式将其发送到服务器。

如果您有用户登录或某种方式可以唯一标识每个用户,建议将其与用户详细信息一起存储。 (以及名称,唯一ID等...)如果您没有登录,您仍然可以将令牌发送到服务器和商店,但是您放弃的是您希望向客户端A而不是B发送更新的情况。

来代码吧。

客户代码:

用于生成gcm令牌:

https://github.com/googlesamples/google-services/tree/master/android/gcm

生成后,您需要将此令牌发送到服务器

服务器代码:

服务器接收令牌并存储。

如果要在以后的某个时间点发送特定消息,可以将json数据或纯文本消息发送给客户端。 例如,以下是python示例。

import gcm
response = gcm.json_request(registration_ids=reg_ids, data=in_data, delay_while_idle=False)

希望这可以帮助。


The requirement is simple.

You need to generate gcm token from each of your client.

Client A installs your application and upon launch/login(wherever it fits in your business logic) you will try to generate this gcm token(let us say 10000 is the generated token) . And you need to send this token to your server to store for using it in future communication. when you want to communicate with this client A, you need to tell gcm server,

Hey Gcm server, send mobile with gcm token 10000 the following message "Event time updated"

So if client b installs, it will generate its gcm token and send it to server in same way.

In case you have user login or some way where each user can be identified uniquely, it is recommended to store it along with user details. (along with name, unique id, etc... ) If you do not have login, you can still send token to server and store but what you loose out is the cases where You want to send update to Client A but not B.

Coming to code point of it.

Client code:

For generating gcm token:

https://github.com/googlesamples/google-services/tree/master/android/gcm

after you generate you need to send this token to server

Server code:

server receives the token and stores.

When you want to send a particular message in later point of time, you can send json data or plain message to client. For example, Following is the python example.

import gcm
response = gcm.json_request(registration_ids=reg_ids, data=in_data, delay_while_idle=False)

Hope this helps.

相关问答

更多

GCM推送通知的问题(Issues with GCM Push Notifications)

作为我评论的附录,因为它有所帮助,我在这里有更多空间: 除了检查令牌是否存在于您的SharedPreferences中之外,您还应该检查您的应用程序的该令牌版本是否与当前运行检查的版本匹配(这是来自Google文档的建议)。 如果设备版本不匹配,您应该请求一个有效的令牌(实际上可能是相同的,但不能保证)。 现在,您可能还想检查PACKAGE_REPLACED广播(如果您在每次安装测试时没有增加清单中的版本,我非常内疚),如果触发,也应该强制您请求新令牌。 至于为什么有时令牌会发生变化而有时候却没有...

GCM推送通知在Android App中无效(GCM push notification not working in Android App)

<permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /> 将com.example.gcm更改为com.scryp: <permission android:name="com.example...

GCM推送通知(GCM Push notification)

问题得到解决,我的请求是错误的。 应该是对GCM服务器的正确请求 { "data": { "message": "Hi I am message", "key2": "value2" }, "registration_ids":["registrationid"] } The problem was fixed the request was wrong from my part. Correct request to GCM server should be { "data": { "me...

GCM推送通知在Android Phonegap应用程序中无效[关闭](GCM push notification not working in Android Phonegap application [closed])

尝试将var app功能移到设备外部。 它会工作。 Try moving that var app functions outside device ready. It will work.

使用Google GCM发送推送通知(Sending push notification using Google GCM)

假设您已经在Google Developers Console上创建了一个新项目,并记录了两个值:Project Number,它将在客户端项目中用作SENDER_ID; 和API服务器密钥(在Credentials中创建),它将在服务器项目中用作API_KEY。 您可以在以下问题中找到有关基本服务器项目的更多信息。 在第二个链接中,您将找到Java中服务器项目的示例代码,然后您可以参考其逻辑以在您的PHP项目中实现: 为Android添加Google云Messagin(GCM) - 注册过程 如...

Xamarin.Android将GCM推送到Azure通知中心(Xamarin.Android push notifications GCM to Azure Notification Hub)

找到了解决方案。 我也必须注册Azure通知中心。 如果有人卡住了,请按照: https://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-notification-hubs-android-get-started/ 或者,按照Xamarin的“Azure Messaging”组件中给出的示例: https : //components.xamarin.com/gettingstarted/azure-messag...

未使用GCM接收推送通知(Not receiving push notification using GCM)

如下更改权限并检查 <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="YOUR_PACKAGE_...

由GCM推送Android应用程序的通知(Push notification for android app by GCM)

要求很简单。 您需要从每个客户端生成gcm令牌。 客户端A安装您的应用程序,并在启动/登录时(无论它适合您的业务逻辑),您将尝试生成此gcm令牌(让我们说10000是生成的令牌)。 并且您需要将此令牌发送到您的服务器以存储以便在将来的通信中使用它。 当你想与这个客户端A通信时,你需要告诉gcm服务器, Hey Gcm server, send mobile with gcm token 10000 the following message "Event time updated" 因此,如果客...

在Android上模拟GCM推送通知(Simulate GCM push notifications on Android)

为了测试接收推送通知,我使用它 。 您可以使用curl或httpie发送请求 http POST 'https://gcm-http.googleapis.com/gcm/send' 'Content-Type:application/json' 'Authorization:key=<your_API_key>' to='<your_device_token>' In order to test receiving push notifications, I use this. You can...

使用GCM和相应的聊天活动推送通知(Push notification with GCM and corresponding Chat Activity)

我在评论中提到过,如果你是通过服务器发送的,你可以这样做: $registatoin_ids = array($regId); $message = array("message" => $message, "productId" => $uniqueProductId); $result = $gcm->send_notification($registatoin_ids, $message); echo $result; 那么在你的意图服务中: Bundle extras = intent...

相关文章

更多

could not find system property or JNDI

Thanks everyone!! Finally got a solution for this p ...

oracle数据库中NOT IN 和 NOT EXISTS为什查不到数据

SELECT GA.ADID, GA.ADNAME FROM GAP_AD GA WHERE e ...

mybatis There is no getter for property named 'xx' in 'class java.lang.String

用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no get ...

Solr拼写检查(spellCheck)配置和使用

Solr具有拼写检查的功能,您只需修改solr的配置文件(solrconfig.xml)中spellc ...

Guava Preconditions类-检查参数

static int checkPositionIndex(int index

微信、微博推出理财产品,互联网金融战或将再度升级

在2013年,互联网最火爆的无疑就是大举进军金融领域,以颠覆性的思维和创新型的方式重新定义了金融规则, ...

solr4.3之拼写检查SpellChecker功能

拼写检查功能,能在搜索时,提供一个较好用户体验,所以,主流的搜索引擎都有这个功能。在这之前,笔者先简单 ...

Apache Solr3.4应用实践(高亮 拼写检查 匹配相似)

Solr 是基于lucene的检索服务器。能够很快的搭建检索服务,并且提供的很多实用的组件。例如高亮( ...

Windows Phone 获取app在商店中的版本(检查app的版本号)

public classAppVersionHelper { /// &lt;summary ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本