Ios 修复核心数据中的SQL注入

Ios 修复核心数据中的SQL注入,ios,core-data,Ios,Core Data,我有一个使用以下字符串构建的谓词 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"displayName == [cd] %@ AND emailAddress == [cd] %@" , displayName, emailAddress]; 在运行我的应用程序时,我会定期遇到一个陷阱,原因如下: Fatal Exception NSInvalidArgumentException unimplemented SQL

我有一个使用以下字符串构建的谓词

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"displayName == [cd] %@ AND emailAddress == [cd] %@" , displayName, emailAddress];
在运行我的应用程序时,我会定期遇到一个陷阱,原因如下:

Fatal Exception   NSInvalidArgumentException
unimplemented SQL generation for predicate : (0x64b5580 <x-coredata://3AA31AFB-35E4-468C-876D-03DEB56F38A3/aaa/p14> IN )

i、 e.用双引号包围搜索目标?或者这里建议使用其他方法?

如果您不确定值的完整性,请尝试使用NSCompoundPredicate。仅当值有效时,才将谓词添加到谓词数组,并从谓词数组创建and复合谓词

NSMutableArray *subPredicates = [NSMutableArray array];

if (displayName) {
    [subPredicates addObject:[NSPredicate predicateWithFormat:@"displayName == [cd] %@",displayName]];
}

if (emailAddress) {
    [subPredicates addObject:[NSPredicate predicateWithFormat:@"emailAddress == [cd] %@",emailAddress]];
}

NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates];

如果不确定值的完整性,请尝试使用NSCompoundPredicate。仅当值有效时,才将谓词添加到谓词数组,并从谓词数组创建and复合谓词

NSMutableArray *subPredicates = [NSMutableArray array];

if (displayName) {
    [subPredicates addObject:[NSPredicate predicateWithFormat:@"displayName == [cd] %@",displayName]];
}

if (emailAddress) {
    [subPredicates addObject:[NSPredicate predicateWithFormat:@"emailAddress == [cd] %@",emailAddress]];
}

NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates];

当引发异常时,能否验证displayName和emailAddress是否有效。占位符插入值的引号,因此不需要包含多余的引号。我希望可以,但我只有crashlytics数据。你说得对,这里有引语,我自己也证实了这一点。我需要找到导致此问题的输入数据。在引发异常时,能否验证displayName和emailAddress是否有效。占位符插入值的引号,因此不需要包含多余的引号。我希望可以,但我只有crashlytics数据。你说得对,这里有引语,我自己也证实了这一点。我需要找到导致此问题的输入数据。感谢这看起来不错-数据来自电子邮件服务器的电子邮件地址/名称,因此它们可以是任何内容。感谢这看起来不错-数据来自电子邮件服务器的电子邮件地址/名称,因此它们可以是任何内容。