tech74
tech74

Reputation: 1375

CFPropertyList usage

i am trying to return a list of users whose accounts have expired from my server to my iphone objective c app using CFPropertyLIst but the data returned in the NSURLConnection callback is always null. I think my use of CFPropertyList may not be correct but can't work out why not

$query="SELECT user, UNIX_TIMESTAMP(created) AS created_ts FROM  accounts"
$result = mysql_query($query)  


$userarray = new CFArray ();
while($row = mysql_fetch_array($result))
{
    $user = $row['user'];
    $created_ts = $row['created_ts'];

   $entry = new CFDictionary();
   $entry->add('user', new CString($user));
   $entry->add('created_ts', new CFNumber($created_ts));
   $userarray->add($entry);

}

$plist = new CFPropertyList();
$plist->add($userarray);
$plist->toXML();
var_dump($plist);

Objective C

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    // We have got everything so no longer need the connection so release it.
    [theConnection release];
    theConnection = nil;

NSString *errorString = nil;
NSArray *array = [[NSPropertyListSerialization 
                       propertyListFromData:theData
                       mutabilityOption:NSPropertyListImmutable
                       format:nil
                       errorDescription:&errorString] retain];

}

Here I'm always getting unexpected character o at line 1 because the format of the plist looks like this which appears ok but still always getting this error

object(CFPropertyList)#5 (17)
{ ["file:protected"]=> NULL
["format:protected"]=> int(0)
["value:protected"]=> array(1) {
[0]=> object(CFArray)#1 (2) { ["iteratorPosition:protected"]=> int(0) ["value:protected"]=> array(1) {
[0]=> object(CFDictionary)#2 (3) {
["iteratorPosition:protected"]=> int(0)
["iteratorKeys:protected"]=> NULL
["value:protected"]=> array(2) {
["user"]=> object(CFString)#3 (1) {
["value:protected"]=>
string(9) "anonymous"
}
["created_ts"]=>
object(CFNumber)#4 (1) {
["value:protected"]=>
int(1281263044)
}
}
}
}
}
}
["iteratorPosition:protected"]=> int(0)
["iteratorKeys:protected"]=> NULL
["content:protected"]=> NULL
["pos:protected"]=> int(0)
["uniqueTable:protected"]=>
array(0) {
}
["countObjects:protected"]=> int(0)
["stringSize:protected"]=> int(0)
["intSize:protected"]=> int(0)
["miscSize:protected"]=> int(0)
["objectRefs:protected"]=> int(0) ["writtenObjectCount:protected"]=>int(0) ["objectTable:protected"]=> array(0) { }
["objectRefSize:protected"]=>int(0)
["offsets:protected"]=>
array(0) {
}
}

Upvotes: 1

Views: 1282

Answers (1)

Seamus Campbell
Seamus Campbell

Reputation: 17916

Your output there is not a plist; it's the internal representation of a CFPropertyList. Have a look at http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/plist.5.html for a short sample plist.

Your problem is that $plist->toXML() does not modify $plist; it returns a string of the XML representation of the $plist object. Change:

$plist->toXML();
var_dump($plist);

to

$xml = $plist->toXML();
var_dump($xml);

Upvotes: 1

Related Questions