0

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

pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65

4 Answers4

4

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];
Joe
  • 56,979
  • 9
  • 128
  • 135
2

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];
Deniss Fedotovs
  • 1,384
  • 12
  • 22
  • done this and it works, thanks! But when it sends the email (because that's what it does), it just says ... Here it is: and then nothing, when it should add the text from the UITextField... Here's the code I used... http://pastie.org/2504653 I declared "messagebody" here: http://pastie.org/2504667. – pixelbitlabs Sep 08 '11 at 20:02
  • Check out that you have declared messagebody before you are initialising *plainpart NSDictionary. Or you need to use NSMutableDictionary if it mutates(changes) after initialising. – Deniss Fedotovs Sep 08 '11 at 20:13
1

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

Delete
  • 922
  • 8
  • 12
1

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.

jamapag
  • 9,290
  • 4
  • 34
  • 28