c++ - Can I call iOS code that contains blocks in a unity wrapper? -


i have method in objective-c goes nsoperationqueue , returns asynchronously block.

eg

+ (void)getdatafromserver:(void(^)(nsarray *data, nserror *error))block;

so when try call this, objective-c++ wrapper,

void get_data(const char *gameobjectname, const char *datacallback,const char *errorcallback){     [libraryclass getdatafromserver:^(nsarray *data, nserror *error) {         if (data) {              unitysendmessage(gameobjectname, datacallback, [[data componentsjoinedbystring:@","] utf8string]);         }         if (error) {             unitysendmessage(gameobjectname, errorcallback, [[error localizeddescription] utf8string]);         }     }]; } 

if breakpoint before block, strings (const char *) populated fine, if breakpoint in if (data) {} section of block, variables munched, looks random data. of course, unitymessagesend() fails because object can't found.

am going right way? suspect i've forgotten or unaware of block/c/c++ caveat.

ideally you'd post implementation of - [myclass getdatafromserver:], @ least want @nielsbot has suggested , copy block stack heap, using -copy:

void get_data(const char *gameobjectname, const char *datacallback,const char *errorcallback){     [libraryclass getdatafromserver:[^(nsarray *data, nserror *error) {         if (data) {              unitysendmessage(gameobjectname, datacallback, [[data componentsjoinedbystring:@","] utf8string]);         }         if (error) {             unitysendmessage(gameobjectname, errorcallback, [[error localizeddescription] utf8string]);         }     } copy]];   // <-- call block's -copy method here } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -