Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting JavaScript from Objective C in PhoneGap using NSString variables
    primarykey
    data
    text
    <p>In a PhoneGap application I am trying to return a line of JavaScript from my .m Objective C file. I can do so with no problem with one variable, but the other one fails silently. There appears to be something antagonistic in how the NSString variable *text is declared, but I am new to Objective C and cannot tell what is wrong with the code. See code below.</p> <pre><code>- (void)umSwipe_receivedSwipe:(NSNotification *)notification { NSLog(@"umSwipe_receivedSwipe called"); NSData *data = [notification object]; NSString *text = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // FAIL: This fails silently NSString* orig = [NSString stringWithFormat:@"alert('%@')", text]; [super writeJavascript:orig]; // This works great NSString* someVar = @"B1234221012341234^LAST/FIRST^151710100000000099000000?;1234221012341234=15171010000000099?"; NSString* concat = [NSString stringWithFormat:@"alert('%@')", someVar]; [super writeJavascript:concat]; } </code></pre> <p>As background, this is to utilize the <a href="http://idtechproducts.com/products/mobile-readers/112.html" rel="nofollow">UniMag Magnetic Strip scanner</a> on iPads.</p> <p>Why would the one variable work while the other does not, when they contain the same character data? How can I incorporate this variable into a string that I send to JavaScript in an iOS PhoneGap application?</p> <p>BTW, I am much more likely to appreciate and understand an answer if it has corrected code in it rather than just a link to something.</p> <p>Thanks.</p> <p>EDIT: So I've discovered that the error is a JavaScript error. Still not sure what the problem is exactly, but the NSString variable must have some sort of invisible character in it that kills the JS experience. Maybe a line-break that doesn't display when I NSLog it...?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload