I have put the following code in...;

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",field.text,     
kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

...and I receive an NSException error saying;

*** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate:     
<NSInvalidArgumentException> +[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil.  Or, did  
you forget to nil-terminate your parameter list?

What does this mean? What do I have to do to fix this issue?

Thanks,

James

有帮助吗?

解决方案

You are trying to format a string in your dictionary initialization and it expects the format to be object, key, object, key, etc... To fix try creating your formatted string on another line for clarity and then adding it as part of the objects and keys as so

NSString *message = [NSString stringWithFormat:@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",
                                                 field.text];
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:
                              @"text/plain", kSKPSMTPPartContentTypeKey,
                              message, kSKPSMTPPartMessageKey,
                              @"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];

其他提示

Maybe you meant something like this:

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain", kSKPSMTPPartContentTypeKey, [NSString stringWithFormat:@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",field.text], kSKPSMTPPartMessageKey, @"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];

You are missing an argument. I count 8 total arguments including nil. That means one of your key value pairs is not complete.

Try firsty create string:

NSString *partMessageKey = [NSString stringWithFormat:@"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %@",field.text];

then put this string to dictionary as object.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top