Reputation: 1403
I am using the following function for sending SMS.
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = @"SMS Text";
controller.messageComposeDelegate = (id)self;
[self presentViewController:controller animated:TRUE completion:nil];
}
It working fine in iOS 7 and above.But it's crashing in iPod running on 6.0.1 with error
* * Assertion failure in NSDictionary *_UIRecordArgumentOfInvocationAtIndex(NSInvocation *, NSUInteger, BOOL)(), /SourceCache/UIKit/UIKit-2372/UIAppearance.m:1118
2014-05-21 11:33:38.170 Project[764:4913] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unknown key, "NSColor" in title text attributes dictionary' * First throw call stack: (0x36c922a3 0x3346997f 0x36c9215d 0x383b430b 0x37717925 0x37716a7b 0x36c8f62f 0x377167f5 0x377f45e5 0x37782cd7 0x37782b6d 0x359d390f 0x37782a61 0x3778c0d5 0x359c683b 0x3778c0b1 0x359c611f 0x359c599b 0x359c5895 0x359d4215 0x359d43b9 0x36163a11 0x361638a4) libc++abi.dylib: terminate called throwing an exception
Any help will be appreciable
Upvotes: 1
Views: 1161
Reputation: 2456
The probable reason is that your picker is nil
. The code will work only on devices that can send text. In regards to the same, you should always check for message sending capability using [MFMessageComposeViewController canSendText]
and only then show the picker. From Apple's MFMessageComposeViewController documentation:
Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NO. If SMS delivery isn’t available, you can notify the user or simply disable the SMS features in your application.
Starting in iOS 5, you can register to be notified of changes to the availability of text message sending by way of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification.
EDIT:
Using UITextAttributeTextColor
instead of NSForegroundColorAttributeName
wherever you're setting NSForegroundColorAttributeName
using probably the UIAppearance
methods in your app should fix the error.
Upvotes: 1
Reputation: 852
Try this:
if ([MFMessageComposeViewController canSendText])
// The device can send sms.
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
// You can specify one or more preconfigured recipients. The user has
// the option to remove or add recipients from the message composer view
// controller.
// You can specify the initial message text that will appear in the message
// composer view controller.
picker.body = @"Hello Text";
[self presentViewController:picker animated:YES completion:NULL];
}
Have you checked +[MFMessageComposeViewController canSendText]?
Reference :
canSendText
Returns a Boolean value indicating whether the current device is capable of sending text messages. + (BOOL)canSendText
Return Value
YES if the device can send text messages or NO if it cannot. Discussion
Always call this method before attempting to present the message compose view controller. A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This method applies only to the ability to send text messages via iMessage, SMS, and MMS.
To be notified of changes in the availability of sending text messages, register as an observer of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification. Availability
Available in iOS 4.0 and later.
Declared In MFMessageComposeViewController.h
Upvotes: 0
Reputation: 10505
You can not use SMS on iPod, it is only for iPhone. You should do something like this:-
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
//TODO: your other code
controller.body = @"SMS Text";
controller.messageComposeDelegate = self;
[self presentViewController:picker animated:YES completion:NULL];
}
Make sure you implement MFMessageComposeViewControllerDelegate on the header of your view controller.
The following links might help too:-
Upvotes: 0