开发者

iOS: NSString over bluetooth then converted to selector, FAILS

Ok- I'm running a simple experiment with iOS GameKit. The steps are these:

-1. I have a NSString 'myFunction' on iPad1.

-2. I shoot it over a bluetooth connection with GameKit to iPad2. Encoding is NSASCIIStringEncoding.

-3. iPad2 receives the message.

-4. iPad2 gets the string 'myFunction' from the data it received, and logs it to the debugger so that I can tell it came through alright. It is decoded using NSASCIIStringEncoding. Good so far.

-5. I convert 'myFunction' to a selector using NSSelectorFromString().

-6. I perform the selector on an object which implements -(void)myFunction{}

-7. iPad2 crashes complaining about not being able to find the function myFunction on the object.

Now, if I hard-code the string 'myFunction' into NSSelectorFromString() on step 5, it works beautifully. I know in my gut this is some encoding problem. I tried encoding the string with NSUTF8StringEncoding, but then not only does the program still crash, but the string is logged as null in step 4.

I looked through all the myriad ways t开发者_如何学JAVAo encode strings in the NSString class reference,

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#

But before I try each one of them in turn to see what sticks to the wall, I was wondering if anyone else has tried to do something like what I'm trying; sending strings over bluetooth to be converted to selectors on the other side and performed.


you will have to serialize and send the data. See if this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜