I am currently trying to pass data from one ViewController to a SMS ViewController provided by Apple (through MFMessageComposeViewController) using NSUserDefaults.
I am successfully passing the name of the person to the SMS textfield within my MFMessageComposeViewController, but for some reason the space in between the persons first name and last name gets deleted (i.e. instead of John Smith, it shows up in the textfield as johsmith).
I have logged out all my values and they show that there is indeed a space between the first name and last name (i.e. printing out John Smith)
Below is my code, hopefully someone else has experienced this weird issue or could point me in the right direction. Thanks!!!
-(void)launchMessengerContacts {
if(![MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:@"Your device doesn't support SMS!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:confirmAction];
[self presentViewController:alertController animated:YES completion:nil];
return;
}
NSString *message = @"Hey! I'm inviting you to play this game!";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setBody:message];
NSUserDefaults *contactsUD = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
NSMutableString *contactName = [contactsUD objectForKey:@"contactName"];
NSLog(@"Contact Name: %@", contactName);
messageController.recipients = [NSArray arrayWithObjects:contactName, nil];
NSLog(@"Message Controller Recs: %@", messageController.recipients);
[self presentViewController:messageController animated:YES completion:nil];
}
In my didselectrowatindexpath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
AddressBookTableViewCell *cell = [tableView
cellForRowAtIndexPath:indexPath];
NSUserDefaults *contactUD = [NSUserDefaults standardUserDefaults];
[contactUD setObject:cell.contactLabel.text forKey:@"contactName"];
NSLog(@"cell : %@", cell.contactLabel.text);
NSLog(@"NSUserDefaults is %@", contactUD);
NSLog(@"User Defaults Contact Name: %@", [contactUD
objectForKey:@"contactName"]);
[self launchMessengerContacts];
}