ios - How can I send a array by WiFi/Bluetooth? -



ios - How can I send a array by WiFi/Bluetooth? -

i utilize multipeer connectivity framework

sending text correctly can send other data

-send text:

nsdata *datatosend = [_txtmessage.text datausingencoding:nsutf8stringencoding]; nsarray *allpeers = _appdelegate.mcmanager.session.connectedpeers; nserror *error; [_appdelegate.mcmanager.session senddata:datatosend topeers:allpeers withmode:mcsessionsenddatareliable error:&error]; if (error) { nslog(@"%@", [error localizeddescription]); } [_txtmessage settext:@""]; [_txtmessage resignfirstresponder];

-receive text:

-(void)didreceivedatawithnotification:(nsnotification *)notification{ mcpeerid *peerid = [[notification userinfo] objectforkey:@"peerid"]; nsstring *peerdisplayname = peerid.displayname; nsdata *receiveddata = [[notification userinfo] objectforkey:@"data"]; nsstring *receivedtext = [[nsstring alloc] initwithdata:receiveddata encoding:nsutf8stringencoding]; }

nsmutablearray *arraysongs; how send , receive array?

sorry bad english

added comment formatting , continuity:

mpmediaquery *everything = [[mpmediaquery alloc] init]; nslog(@"logging items generic query..."); nsarray *itemsfromgenericquery = [everything items]; (mpmediaitem *song in itemsfromgenericquery) { nsstring *songtitle = [song valueforproperty: mpmediaitempropertytitle]; nsstring *artist = [song valueforproperty:mpmediaitempropertyartist]; long totalplaybacktime = [[song valueforproperty: mpmediaitempropertyplaybackduration] longvalue]; [arraysongs addobject:song]; }

type array

mpmediaquery * todo = [[alloc mpmediaquery] init];

nslog (@ "elementos de registro de una consulta genérica ..."); nsarray * itemsfromgenericquery = [elementos de muebles]; (mpmediaitem * canción en itemsfromgenericquery) {nsstring * songtitle = [canción valueforproperty: mpmediaitempropertytitle]; nsstring * artista = [canción valueforproperty: mpmediaitempropertyartist]; largo totalplaybacktime = [[canción valueforproperty: mpmediaitempropertyplaybackduration] longvalue]; [arraysongs addobject: song]; }

you can serialize nsarray json info datawithjsonobject:options:error: send data restore nsarray jsonobjectwithdata:options:error:.

this assuming components of nsarray supported json serialization.

for array has more complex objects utilize nsarchiver , add together back upwards nscoding objects not implement protocol.

mpmediaitem conforms nscoding can serialize nsarchiver json.

ios arrays bluetooth wifi multipeer-connectivity

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -