检查是否存在财产(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
满意答案
要求很简单。
您需要从每个客户端生成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)
GCM推送通知在Android App中无效(GCM push notification not working in Android App)
GCM推送通知(GCM Push notification)
GCM推送通知在Android Phonegap应用程序中无效[关闭](GCM push notification not working in Android Phonegap application [closed])
使用Google GCM发送推送通知(Sending push notification using Google GCM)
Xamarin.Android将GCM推送到Azure通知中心(Xamarin.Android push notifications GCM to Azure Notification Hub)
未使用GCM接收推送通知(Not receiving push notification using GCM)
由GCM推送Android应用程序的通知(Push notification for android app by GCM)
在Android上模拟GCM推送通知(Simulate GCM push notifications on Android)
使用GCM和相应的聊天活动推送通知(Push notification with GCM and corresponding Chat Activity)
相关文章
更多could not find system property or JNDI
oracle数据库中NOT IN 和 NOT EXISTS为什查不到数据
mybatis There is no getter for property named 'xx' in 'class java.lang.String
Solr拼写检查(spellCheck)配置和使用
Guava Preconditions类-检查参数
微信、微博推出理财产品,互联网金融战或将再度升级
solr4.3之拼写检查SpellChecker功能
Apache Solr3.4应用实践(高亮 拼写检查 匹配相似)
Windows Phone 获取app在商店中的版本(检查app的版本号)
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!