1

I want to send a PFObject directly over a push notification. I send the Parse object directly inside the push (e.g. with a custom key "arg") but I couldn't figure out how to construct a real PFObject from the received data. Received data is (obviously) an NSDictionary, with all the keys (object ID, created at, ACLs etc) available. How do I convert it to a PFObject instance?

I need a real way to construct a PFObject with the available data, so don't come with obvious solutions like "send the object ID and then fetch that object at client with Parse's methods." etc. I already know that obvious solution, but it's time/bandwidth/quota inefficient as it requires a new query, while I can have everything I need in that query anyway.

I'm looking for an automatic way, if any. I am targeting iOS 8 so maximum push payload size is also not an issue (2KB is more than enough for my case).

UPDATE: I've tried [PFObject objectWithClassName:@"MyClassName" dictionary:receivedDictionaryObject]; but no avail. It just does not work, the fields are nil even though the dictionary has all the data directly from Parse itself.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • Have you tried posting this on the google groups? The parse devs, more specifically hector, is usually pretty active answering questions on there. They no longer use SO as a resource. https://groups.google.com/forum/#!forum/parse-developers – soulshined Feb 01 '15 at 19:17
  • @soulshined just posted it. – Can Poyrazoğlu Feb 02 '15 at 01:27

1 Answers1

0

I think you can use something like this

+ (PFObject *)objectFromDictionary:(NSDictionary *)dictionaryFromPush{
    PFObject *theObject = [[PFObject alloc] initWithClassName:@"MyClassName"];
    for( NSString *keys in [dictionaryFromPush allKeys] )
    {
        [theObject setObject:[dictionaryFromPush objectForKey:keys] forKey:keys];
    }
    return theObject;
}

This is an untested code but im pretty sure will give you and idea of my point, to get the NSDcitionary from the Push and sent it to this method to be able to convert it to a PFObject

Hope this help

Vincent
  • 206
  • 2
  • 8