Send SMS programmatically, without the SMS composer window
In fact it is not possible; however it was when the question was answered.
The App in question has now specified in its description that it won't work under IOS 6, so I think apple patched some bug that could be exploited to achieve this functionality.
Is there any way to send a text message programmatically without having to open the default sms app in iphone?
The way to do this is by sending the SMS not directly from the user's phone but from a distant SMS server. Notice that it also means that you will be the one paying for the text messages being sent, and not the users.
iphone 4.0 sending sms programmatically
The two options available in the iOS API are:
MFMessageComposeViewController
- requires user confirmationsms://
URLs - requires user confirmation
If you want to do something else, you'll need to set up a network-based service with an SMS gateway provider and send messages via that. I used to work with such a provider that had an HTTP POST interface, which would be simple enough to use. That comes with a couple of important differences:
- the SMS is actually sent by the gateway server, not the handset (though you can usually rewrite the sender ID and get the message billed to the handset owner)
- you'll need to pay for access to the service, which might include paying per message (or more likely per 1,000 messages)
Also note that sending SMS on your users' behalf without confirmation might be frowned upon when your app is reviewed, especially if they're billed for.
Send sms programmatically on iphone
Here is a sample project sendspace.com/file/i6s6j7 Tested it on iPhone 5 with iOS 7.0.4. There is one thing you need to take care of - "Run Script" build phase. This is where application is signed. I used codesign
which will probably not work for you.
In case of a logos tweak you can't sign your tweak with any entitlements you want. Your code will use and is limited to entitlements of application your are hooking. If it's SpringBoard then it's SpringBoard's entitlements that lack com.apple.CommCenter.Messages-send
. So for a SpringBoard tweak my solution with CTMessageCenter
will not work. But XPC solution in my answer here will work. Unfortunately, SMS sent using XPC will show up in SMS database.
There are two possible solutions:
- Daemon. You can sign it with any entitlements you want and do pretty much anything you want.
- Write a tweak to another daemon just for SMS sending. Possible candidate -
com.apple.imagent
located in/System/Library/PrivateFrameworks/IMCore.framework/imagent.app/imagent
. It signed with all the entitlements we need for SMS sending which is obvious because this daemon deals with SMS on lower level. It observes incoming SMS notifications, XPC calls like in my answer and other Instant Messaging related stuff.
How to programmatically send a text message after the user has given permission?
The answer to this question is that you can't. There are some jailbreak apps that accomplish this but they require just that, a jailbreak (and private APIs). There is no App Store allowed way to do this.
How to programmatically send SMS on the iPhone without MFMessageComposeViewController ?
It's not possible to send SMS messages programmatically through the iOS SDK. As you can imagine, if the SDK allowed this, it would open a huge can of worms in terms of developer abuse.
If the SMS messages don't have to come from the user's phone number, you can take a look at the Twilio API (http://www.twilio.com/sms).
How to send SMS programmatically using IOS Simulator
Ios similator can not send messages but you can send it by running your project in divice by using this code.
Add MessageUI framework in your project
Then in your .h file add this
#import <MessageUI/MessageUI.h>
@interface MessageViewController : UIViewController<MFMessageComposeViewControllerDelegate>
- (IBAction)SendTextBtnTapped:(id)sender;
@end
And in your .m file add this
- (IBAction)SendTextBtnTapped:(id)sender {
[self sendSMS:@"" recipientList:[NSArray arrayWithObjects: nil]];
}
//for sms
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
controller.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentModalViewController:controller animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
if (result == MessageComposeResultCancelled)
NSLog(@"Message cancelled");
else if (result == MessageComposeResultSent)
NSLog(@"Message sent");
else
NSLog(@"Message failed");
}
Related Topics
How to Add Exception Breakpoint in Xcode
Getting the Difference Between Two Dates (Months/Days/Hours/Minutes/Seconds) in Swift
Difference Between 'Yyyy' and 'Yyyy' in Nsdateformatter
Xcode 6 Bug: Unknown Class in Interface Builder File
How to Convert String Date to Nsdate
Wait For Firebase to Load Before Returning from a Function
How to Find Specific Subclass of Nsmanagedobject
How to Validate an Url on the Iphone
How to Get a Unique Device Id in Swift
How to Produce an Effect Similar to the iOS 7 Blur View
How to Develop For Iphone Using a Windows Development Machine
Opening the Settings App from Another App
Fast and Lean Pdf Viewer For Iphone/Ipad/Ios - Tips and Hints
How to Easily Resize/Optimize an Image Size With Ios
How to Navigate Through Textfields (Next/Done Buttons)
Returning Method Object from Inside Block