检索用户对象ID
var
ACreatedObject: TBackendEntityValue; // REST.Backend.MetaTypes
begin
BackendUsers.Users.LoginUser('donald','#duck99',ACreatedObject);
fUserObjectId:=ACreatedObject.ObjectID;
end
更新与用户对象ID
安装假设你在安装的表有一栏“用户”上解析为一个指向_User类的指针。
内PushEventsDeviceRegistered事件:
var
JO,JOP:TJSonObject; // System.JSON
O:TBackendEntityValue; // REST.Backend.MetaTypes
begin
if PushEvents.InstallationValue.TryGetObjectID(fInstallationObjectId) then
begin
try
JO:=TJSONObject.Create;
JOP:=TJSONObject.Create;
JOP.AddPair('__type','Pointer');
JOP.AddPair('className','_User');
JOP.AddPair('objectId',fUserObjectId);
JO.AddPair('User',JOP);
BackendStorage.Storage.UpdateObject('_Installation',
fInstallationObjectId,JO,O);
finally
JO.Free;
end;
end
end;
要根据用户名
注意,你可以通过创建JSON对象目标目标Push消息,但我已经使用了字符串与格式在这里。
const
Target = '{"where":{"User":{"$select":{"query":'+
'{"__type":"Pointer","className":"_User","where":'+
'{"username":"%s"}},"key":"objectId"}}}}';
begin
BackendPush.Target.Text:=Format(Target,['donald']);
BackendPush.Message:='Gratz on the Election Result';
BackendPush.Push;
end
非本地变量/声明
以下德尔福巴斯组分在设计时创建的。
ParseProvider: TParseProvider;
PushEvents: TPushEvents;
BackendUsers: TBackendUsers;
BackendStorage: TBackendStorage;
BackendPush: TBackendPush;
下面的类(或全局)变量被称为:
fUserObjectId:string; // Must be set before push registration is activated.
fInstallationObjectId:string;
注:原代码是完全测试,但我已经剪切/粘贴(和编辑,以去除不相关东西)所以原谅我,如果有任何剪切/粘贴错误。
这次不知道我是否正确地得到了这个问题,但是如何将设备注册到特定频道(f.i.用户名)然后发送到这个频道? –
虽然跟着@Uwe Raabe给我的带领 - 我找到了答案。 安装ID隐藏在PushEvents对象中,这里是需要在PushEvents对象的DeviceRegistered事件中执行的代码。: '如果PushEvents.InstallationValue.TryGetObjectID(fInstallationObjectId)then' 然后将以下更新安装对象: 'JOP.AddPair( '__类型', '指针'); JOP.AddPair('className','_ User'); JOP.AddPair('objectId',fUserObjectId); JO.AddPair('User',JOP); BackendStorage.Storage.UpdateObject('_ Installation',fInstallationObjectId,JO,O);' –
@ChristopherBurke很高兴您找到了解决方案,并且非常欢迎。你知道你可以回答你自己的问题吗? http://stackoverflow.com/help/self-answer 如果你这样做,你的答案会更容易阅读,你可能会得到进一步的答案投票。 – BIBD