MFMessageComposeViewController shows blank white screen in iOS7 - iphone

there's a problem when I try to send a large recipients list (e.g more than 40) using MFMessageComposeViewController. In iOS7, it will show a blank white screen for 20s or more before displaying the SMS compose view. This does not occur for iOS5 and iOS6.
Below is the existing code that I'm using,
NSArray * recipients;
for (NSIndexPath * index in selectedRows)
{
NSDictionary *dictionary = [data objectAtIndex:index.row];
NSString *phoneNum = [dictionary objectForKey:#"contactNum"];
recipients = [NSArray arrayWithObjects:phoneNum, nil]];
}
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self ;
controller.wantsFullScreenLayout = NO;
[(id)_delegate presentModalViewController:controller animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Below are the output message that I received when I try to send to many.
timed out waiting for fence barrier from com.apple.mobilesms.compose
Received memory warning.
Received memory warning.
Received memory warning.
Received memory warning.
Received memory warning.
Received memory warning.
Received memory warning.
Received memory warning.
Received memory warning.

I had a similar problem where I got the message in the console "
timed out waiting for fence barrier from com.apple.mobilesms.compose
The problem was that I tried in my app to add the number as a string, but because of the localization request, I have put it in a form:NSArray *recipents = #[NSLocalizedString(#"numberForRegistrationViaSms", #"")];
and
[messageController setRecipients:#[recipents]];
That didn't work for some reason but, when I put just simply, [messageController setRecipients:#[#"123456789"]];, the SMS composer appears without any problem.

I to had the same problem then figured
controller.recipients = // should always be an array of strings.
Make sure the phone numbers you send to controller.recipients are NSString.

I think I maybe resolve this:
//must initiate new NSString object
NSString *phoneStr = [NSString stringWithFormat:#"%#",... ];
MFMessageComposeViewController *aCtrl = [[MFMessageComposeViewController alloc] init];
aCtrl.recipients = #[phoneStr];
...
Then OK.

I had same problem.
timed out waiting for fence barrier from com.apple.mobilesms.compose
Message Cancelled
Instead of this:
NSString *phoneNumber = #"888888888";
[picker setRecipients:#[phoneNumber]];
Try this:
NSString *phoneNumber = person.phoneNumber;
[picker setRecipients:#[[NSString stringWithFormat:#"%#", phoneNumber]]];
This worked for me.

The problem has been resolved in iOS 7.0.3.

Related

Sending SMS to dynamic Telephone number

I have an app which sends an sms and then calls a dynamic telephone number, here is the code:
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = #"Your Message here";
[messageComposer setBody:message];
messageComposer.recipients = [NSArray arrayWithObjects:#"0003233", nil];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
NSLog(#"Texting telephone number [%#]", messageComposer);
NSString *urlString = [NSString stringWithFormat:#"tel://%#", number];
NSLog(#"calling telephone number [%#]", number);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
NSLog(#"%#", [self deviceLocation]);
}
the telephone call works but not the sms, can anyone help?
First check if your device can send SMS messages by:
if ( [MFMessageComposeViewController canSendText] ) {
// build your text message like you posted
}
else {
// handle appropriately
// no point in trying to display the compose view controller
}
Whether this solves your specific problem, I am not sure, since I am just following Apple's docs for this.
just replace this line in your method and you'll be able to send dynamic messages
messageComposer.recipients = [NSArray arrayWithObjects:number,nil];
and you can send emails and messages automatically without pressing send button but in that case there is a chance of rejecting of your app from the apple app store as it is not under their legal process so they'll reject your application.
and you should check condition for
if([MFMessageComposeViewController canSendText])
otherwise in iPad and iPod your application might meet crash.

Simulating sent SMS on iPhone

Since debugging is extremely slow with Xcode 4.3 on iOS 5.1 when starting/installing the app on the device I use the simulator which starts much faster. (see my question regarding this issue here https://stackoverflow.com/questions/11541288/xcode-4-3-with-ios5-1-pauses-about-10secs-when-debug-starts-simulator-starts-i)
So all I need to do is something like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MessageComposeResult result = MessageComposeResultSent; <-----------
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
Here the problem is now that when executing on iOS-Simulator the MFMessageComposeViewController can't be instantiated and always yields nil.
Is there a way to create another object MyOwnMFMessageComposeViewController on iOS simulator which is compatible to MFMessageComposeViewController and can be passed in the same method like MFMessageComposeViewController?
Something like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MyOwnMFMessageComposeViewController *mypicker = [[MFMessageComposeViewController alloc] init];
mypicker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
mypicker.recipients =[NSArray arrayWithObject: s];
mypicker.body =smsTxt;
MessageComposeResult result = MessageComposeResultSent;
picker = (MFMessageComposeViewController) mypicker;
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
What you are looking for is called a 'mock object' and is often used in test driven development. Basically what you do is create a subclass of MFMessageComposeViewController. This subclass works exactly the same as mfmessagecomposeviewcontroller except you also create instance variables to show that something has happened.
So for example when your delegate calls messageComposeViewController:didFinishWithResult. The mock object would likely store the result and a flag that that method had been fired. Note that this won't actually send anything, but simply tells you that the delegate fired and on a real object will work.

Iphone sms app issue

iam making an application where i have to send a same body sms to my contact list . I m using
Class messageClass = (NSClassFromString(#"MFMessageComposeViewController"));
if (messageClass != nil)
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
if ([appdelegate.NumberArray count] > 0) {
NSString *aa = [appdelegate.NumberArray objectAtIndex:0];
NSMutableArray *myArray = [aa componentsSeparatedByString:#","];
NSString *n = [myArray objectAtIndex:0];
NSString *m=[myArray objectAtIndex:1];
NSString *new = [appdelegate.globalmsg stringByReplacingOccurrencesOfString: #"forgot" withString:n];
controller.body = new;
controller.recipients= [NSArray arrayWithObject:m];
controller.messageComposeDelegate = self;
//if([appdelegate.NumberArray count] ==2 ){
[self presentModalViewController:controller animated:YES];
im taking out my contact one by one from my mutable array . the problem is that my program sending an sms one at a time, not to the complete list. and if i wanted to send sms to next person i have to click send button again. is there any way i can send sms to everyone without clicking that send button again again?
u can check this app .... http://itunes.apple.com/us/app/automatic-custom-sms/id409247779 in this app last page comes automatically and send everyone from your contact list. ??
Ok i fix it. i use a local variable an initialize it in view did load with value 0 and then in view did appear update it to 1 and make making present model view appear till my array finished.

How do I generate an SMS message based on a template in an iPhone app?

I'm trying to make an iPhone app where a user can use a built-in template for sending SMS messages. For example:
Dear [recipient name]
I would like to meet you.
Yours sincerely,
[recipient name]
I want to change [recipient name] to the person the user is sending the SMS message to.
How would I generate the string to be sent in the SMS message, and how would I send it?
if any one looking for the code i have done it myself.
if (appdelegate.dataarray.count>0) {
NSMutableArray *dataarrrr = [appdelegate.dataarray objectAtIndex:0];
NSLog(#"%#",[dataarrrr objectAtIndex:0]);
NSString *aa = [dataarrrr objectAtIndex:0];
NSMutableArray *myArray = [aa componentsSeparatedByString:#","];
NSString *n = [myArray objectAtIndex:0];
NSString *m=[myArray objectAtIndex:1];
NSString *Message = [dataarrrr objectAtIndex:1];
NSString *new = [Message stringByReplacingOccurrencesOfString: #"<Dear User>" withString:n];
controller.body = new;
controller.recipients= [NSArray arrayWithObject:m];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
See the MFMessageComposeViewController, you can set the SMS body before displaying the message composer. I don’t think there’s a better way to send text messages, see this related question.

iPhone application lags after launching and dismissing MFMailComposeViewController

I have an application that uses a table view controller to display some items, after clicking on one of those items you may select to email this item. Once that happens I use the code provided by apple "MailComposer", and send the mail. However after this the scrolling in the table view is not as smooth as before.
I checked with "Leaks" and there are no leaks in my code, however there is a great deal of object allocation when the modal view controller for the MFMailComposeViewController, and when i dismiss my controller, all that object allocation is still there. How can i get rid of all that object allocation?. Any help will be greatly appreciated. Thank you.
-Oscar
UPDATE:
I have realized the lag only happens once you click on the To: textfield on the MFMailComposeViewController and type something, once something has been typed there will be a memory leak and the application will be sluggish. This exact same thing also happens in Apple's Mail Composer. I am using the simulator maybe this is why?. Does anyone else have a simmilar experience?
The way I am pressenting my controller is:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *mailSubject = appDelegate.mailTitle;
NSString *mailBody = appDelegate.mailLink;
NSString *formattedString = [NSString stringWithFormat:#"<a href='%#'>%#</a>", mailBody, mailBody];
[picker setSubject:mailSubject];
// Set up recipients
//NSArray *toRecipients = [NSArray arrayWithObject:#"somemail#hotmail.com"];
//NSArray *ccRecipients = [NSArray arrayWithObjects:#"second#example.com", #"third#example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObject:#"fourth#example.com"];
//[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email (Warning this causes a memory leak aknowledged by Apple)
//NSString *path = [[NSBundle mainBundle] pathForResource:#"news_icon" ofType:#"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:#"image/png" fileName:#"rainy"];
// Fill out the email body text
[picker setMessageBody:formattedString isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
and dimissing it here:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
....
[self dismissModalViewControllerAnimated:YES];
}
It's a known memory leak in MFMailComposeViewController class (as of iOS 4.2 SDK). The leaks can be even seen in the MailComposer sample project by Apple. Try to run the app with Allocations instrument and notice the Overall Bytes growing up every time you click cancel and show the composer again.
See below for the similar discussion:
http://discussions.apple.com/thread.jspa?threadID=2158170
https://devforums.apple.com/thread/23510?tstart=15
https://devforums.apple.com/message/121093#121093
Make sure you use
controller.mailComposeDelegate = self;
and not
controller.delegate = self;