以阿拉伯语提交文本字段时,iOS 应用程序崩溃 [英] iOS app crashing when submitting textfield in Arabic
问题描述
我的应用是电子商务应用.当我从 iOS 添加新产品时,如果我用英文填写描述字段,它会成功发布产品,但是当我尝试使用阿拉伯语并单击提交按钮后,它会崩溃并显示 Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
My app is an e-commerce app. When I add a new product from iOS if I fill the description field in English it post the product successfully, but when I try Arabic and after clicking the submit button it crashes with Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
removeQuotesFromHTML 在调用时中断
removeQuotesFromHTML breaks when called
(NSString *)removeQuotesFromHTML:(NSString *)html {
html = [html stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
html = [html stringByReplacingOccurrencesOfString:@""" withString:@"""];
html = [html stringByReplacingOccurrencesOfString:@""" withString:@"""];
html = [html stringByReplacingOccurrencesOfString:@"\r" withString:@"\\r"];
html = [html stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];
return html;
}
第一个断点发生在下面的代码中,在 delegat.postProductArray 我认为当 getHTML 被调用时它实际上会中断
the first breakpoint happens in the following code, at delegat.postProductArray i think it actually break when getHTML is called
(void) SaveProductBtnTapped
{
[self.view endEditing:YES];
[delegate.postProductArray replaceObjectAtIndex:3 withObject:[self getHTML]];
NSString * message=@"";
if([delegate.addProductPhotos count]==0){
message=[delegate.languageDict objectForKey:@"uploadimage"];
}else if([[delegate.postProductArray objectAtIndex:2] isEqualToString:@""] || [[delegate.postProductArray objectAtIndex:2] isEqualToString:[delegate.languageDict objectForKey:@"what_are_you_selling"]]){
message=[delegate.languageDict objectForKey:@"titlecannotblank"];
}else if([[self getText] isEqualToString:@""]){
message=[delegate.languageDict objectForKey:@"descriptioncannotblank"];
}else if([[NSString stringWithFormat:@"%@",[delegate.postProductArray objectAtIndex:4]] isEqualToString:@""]&&!freeProduct){
message=[delegate.languageDict objectForKey:@"pricecannotblank"];
}
else if([[delegate.postProductArray objectAtIndex:4]integerValue]==0&&!freeProduct)
{
//Entrez le prix valide
message=[delegate.languageDict objectForKey:@"entervalidprice"];
}
else if([[NSString stringWithFormat:@"%@",[delegate.postProductArray objectAtIndex:5]] isEqualToString:@""]){
message=[delegate.languageDict objectForKey:@"currencycodenotselected"];
}else if([[NSString stringWithFormat:@"%@",[delegate.postProductArray objectAtIndex:0]] isEqualToString:@""]){
message=[delegate.languageDict objectForKey:@"select_category"];
}else if([[delegate.postProductArray objectAtIndex:7] isEqualToString:@""]||[[delegate.postProductArray objectAtIndex:7]isEqualToString:@"North Atlantic Ocean"]){
message[delegate.languageDictobjectForKey:@"locationnotselected"];
调用 removeQuotesFromHTML 时出现以下中断
and the following breaks when calling removeQuotesFromHTML
(NSString *)getHTML
{
NSString *html = [self stringByEvaluatingJavaScriptFromString:@"zss_editor.getHTML();"];
//NSString *html = [editorView stringByEvaluatingJavaScriptFromString:@"zss_editor.getHTML();"];
html = [self removeQuotesFromHTML:html];
html = [self tidyHTML:html];
return html;
}
推荐答案
试试这个:
NSString * newHTML = [NSString stringWithFormat:@"%@", html];
newHTML = [newHTML stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
//...... all replaces
return newHTML;
这篇关于以阿拉伯语提交文本字段时,iOS 应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!