Iphone sms app issue - iphone

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.

Related

MFMessageComposeViewController shows blank white screen in iOS7

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.

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 Url Scheme with Body Content?

I am looking to pre-fill the SMS body with content given "smsto:555-555-5555:Hello World"
I have done my research and everybody says it cannot be done but I have a QR reader on my phone right now that can take "sms:555-555-5555:Hello world" and pre-fills the content with the correct phone number scanned.
So my question is. How do i do this? it is pretty clear that the URL scheme provided doesn't handle the body. What other methods are out there to pre-fill the body? it can clearly be done with the QuickMark Reader.
You can use the modalViewController for SMS to fill the body of a text.
add the MessageUI framework to your project.
set you viewController as the MFMessageComposeDelegate
Create the modal view and present it:
-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = delegate;
[delegate presentModalViewController:controller animated:YES];
}
}
You can't launch the Messages app with a predefined message according to Apple Documentation.
What you can do is implement the handling yourself and parse the URL like the following:
NSURL *url = /* the url you get from the web (in webview delegate) or after QR Code scan */;
if ([url.scheme isEqualToString:#"sms"]) // is it a sms ?
{
if([MFMessageComposeViewController canSendText]) // can I send text message ?
{
NSArray *parts = [url.absoluteString componentsSeparatedByString:#":"];
NSString *messageText = parts.count == 3 ? [parts objectAtIndex:2] : #"";
NSString *telNumber = parts.count >= 2 ? [parts objectAtIndex:1] : #"";
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
}
And voilà !

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.