How many characters can NSString have
I am trying to return a string from Javascript:
[myWebView stringByEvaluatingJavaScriptFromString:@"myJavaScriptFunction()"];
for short strings, the return is OK. However, when I return a very long string(say 5000 characters in the string), I couldn't get anything.
So I am guessing it might due to the NSString Size limitation OR开发者_JAVA技巧 my "var jvString" size limitation.
Please help. Thanks
When the method stringByEvaluatingJavaScriptFromString
returns nil
, it means something has gone wrong. This is most likely not because of NSString
size limitations, but for one of the following reasons:
- the javascript execution took longer than 10 seconds
- the script allocated more than 10 MB
From the documentation:
JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script. This is likely to occur at a random place in your code, so unintended consequences may result. This limit is imposed because JavaScript execution may cause the main thread to block, so when scripts are running, the user is not able to interact with the webpage.
JavaScript allocations are also limited to 10 MB. The web view raises an exception if you exceed this limit on the total memory allocation for JavaScript.
Due to the 32 bit structure it should have a max length of 2^31-1 characters which should be enough ;)
精彩评论