我的应用程序必须生成一个 qr 代码,我使用此块成功实现了该代码
NSString *info = [NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@", [_sighting valueForKey:@"Sighting_id"], [_sighting valueForKey:@"Name"], [_sighting valueForKey:@"Type"], [_sighting valueForKey:@"Distance"], [_sighting valueForKey:@"Loc"], session.userId];
NSLog(@"%@", info);
NSData *qrCodeData = [info dataUsingEncoding:NSISOLatin1StringEncoding];
CIFilter *qrCodeFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrCodeFilter setValue:qrCodeData forKey:@"inputMessage"];
[qrCodeFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
CIImage *qrCodeImage = qrCodeFilter.outputImage;
CGRect imageSize = CGRectIntegral(qrCodeImage.extent);
CGSize outputSize = CGSizeMake(240.0, 240.0);
CIImage *imageByTransform = [qrCodeImage imageByApplyingTransform:CGAffineTransformMakeScale(outputSize.width/CGRectGetWidth(imageSize), outputSize.height/CGRectGetHeight(imageSize))];
UIImage *qrCodeImageByTransform = [UIImage imageWithCIImage:imageByTransform];
self.qrimage.image = qrCodeImageByTransform;
[_sighting valueForKey:@"Name"],这是包含阿拉伯字符串的代码,一旦使用,二维码将不会显示,不会出现崩溃或任何失败迹象。