Im trying to send an sms programmatically and in ios 6 its works perfect but in ios 7 its not working. Its open a white view with nothing inside and just stuck my app!
my code looks like this:
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
[messageVC setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
NSString *smsString = [NSString stringWithFormat:#"bla bla bla"];
messageVC.body = smsString;
messageVC.recipients = #[userPhone];
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
}
please help!! ios7 driving me crazy!
Your code works fine, but the message "Text messaging is not available" is given on devices that are not capable to send messages. I tested on an iPad Mini and it's working fine.
Related
I am sending SMS programmatically like this for a long time now. It worked without any problems in iOS6.
But now after update to iOS7 some users have probelms with the app. They need to deinstall the app - reboot the iPhone - reinstall it and then it works.Just reinstalling it without rebooting the phone does not work either.
What could be the reason for this really annoying problem?
Furthermore there are a few cases where they can send several SMS after this procedure but then the iPhone SMS-Dialog appears very slowly and no SMS is being sent again, until they restart the iPhone. Just stopping and restarting the app does not help.
Here's the normal SMS code:
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
[messageVC setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
NSString *smsString = [NSString stringWithFormat:#"bla bla bla"];
messageVC.body = smsString;
messageVC.recipients = #[userPhone];
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
}
I even released a new Version of the app with the newest Xcode 5.0 with Deployment Target 5.1, since I need to support iOS5.1 users still.
There isn't enough information to tell what's causing the problem. Btw, why are you setting messageComposeDelegate twice?
This is apple's most recent sample code that I've modified worked on my own devices running iOS 7 and iOS 8. Make sure to import MessageUI.framework.
/* -------------------------------------------------------------------------------
showSMSPicker:
IBAction for the Compose SMS button.
------------------------------------------------------------------------------- */
- (IBAction)showSMSPicker:(id)sender
{
/* Checks that the current device can send SMS messages. If no, [[MFMessageComposeViewController alloc] init] will return nil and the app will
crash when -presentViewController:animated:completion: is called with a nil view controller */
if ([MFMessageComposeViewController canSendText])
// The device can send email.
{
[self displaySMSComposerSheet];
}
else
// The device can not send email.
{
self.feedbackMsg.hidden = NO;
self.feedbackMsg.text = #"Device not configured to send SMS.";
}
}
/* -------------------------------------------------------------------------------
displayMailComposerSheet
Displays an SMS composition interface inside the application.
------------------------------------------------------------------------------- */
- (void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
/* One or more preconfigured recipients can be specified. The user has the option to remove
or add recipients from the message composer view controller */
/* picker.recipients = #[#"Phone number here"]; */
// Message body
picker.body = #"This is a message about how great this app is. Please download it by clicking on the link below.";
[self presentViewController:picker animated:YES completion:nil];
}
/* -------------------------------------------------------------------------------
messageComposeViewController:didFinishWithResult:
Dismisses the message composition interface when users tap Cancel or Send.
Proceeds to update the feedback message field with the result of the
operation.
------------------------------------------------------------------------------- */
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result
{
self.feedbackMsg.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MessageComposeResultCancelled:
self.feedbackMsg.text = #"Result: SMS sending canceled";
break;
case MessageComposeResultSent:
self.feedbackMsg.text = #"Result: SMS sent";
break;
case MessageComposeResultFailed:
self.feedbackMsg.text = #"Result: SMS sending failed";
break;
default:
self.feedbackMsg.text = #"Result: SMS not sent";
break;
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
Here is how i use my IPC:
ipc = nil; // reset (camera may be running)
ipc = [[UIImagePickerController alloc] init];
[ipc setDelegate:self];
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:ipc animated:YES completion:^(void){
[self cancelShoot];
}];
It works well on 3GS with iOS 6, also i have no issues on iOS 7 simulator. While testing on iOS 7 devices (iPod 5 gen, iPhone 4, iPhone 5) it always crashes.
Is there anything new to the latest OS that i should be aware of?
Is "ipc" a pointer? Given how you are setting sourceType it looks like it isn't..
This question already has answers here:
How to programmatically send SMS on the iPhone?
(18 answers)
Closed 9 years ago.
I am a IOS Developer seeking for the Messaging api in ios,I had gone through the internet and find that functionality in other possible domains as Java,php,android but,not in IOS Sector.so, can you tell me the solution for the SMS API to send message to other mobiles
Note that you can't automatically send SMS without user's knowledge. You can involve the user & then make him/her do the deed...
Sending SMS in iOS is pretty simple. You would require MFMessageComposeViewController for action. Below we have 2 delegate methods - one for composing your SMS & other when the control comes back to you after the user action.
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated: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")
}
There are plenty of online tutorials with full code to quick start you. Here's one. Hope this helps...
Can I show this "Share Screen" in my own app using iOS 6? Somebody that knows how?
I'm afraid you are all wrong. I'm sorry for being this negative, but your wrong answers forced me to waste time in going for futile solutions.... instead you can use this code to achive this screen:
NSString* someText = self.textView.text;
NSArray* dataToShare = #[someText]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];
The code is from Social.framework.
See this answer: Using Apple icons with iOS 6
Hi all
Working on a universal build for an iphone/ipod/ipad app. I was trying to get game center working within this app. I now have the game center working on the ipad but for some reason it still wont work on the ipod/iphone and i have no idea why.
highScoreVC=[[UIViewController alloc] init];
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:highScoreVC.view];
[highScoreVC presentModalViewController:leaderboardController animated: YES];
}
this is my code for displaying the leaderboard and it does work everytime for ipad but as i said not for other devices. the code is still being called the same as for ipad so i have no clue why it is not displaying. any ideas why this would be? cheers
As far as I'm concerned, [GKLeaderboardViewController init] will return nil if the device is not authenticated with Game Center by that point. Are you sure you are correctly authenticated on the devices causing problems?
I suspect there may be some issues with how your UIKit items for Game Center are being displayed if they are working fine on the iPad but not iPhone/iPod. I experienced similar sounding issues when converting an app to universal.
If you create a new standalone iPhone/iPod project just for testing does game center display fine?
ok i got it working in the end.
cocos2d 0.99.5 has indeed made some changes that to how this works. the following code displays the leaderboard correctly
-(UIViewController*) getRootViewController{
return (UIViewController*)([(BubbleDreamsAppDelegate*) [[UIApplication sharedApplication] delegate] viewController]);
}
and then
highScoreVC = [self getRootViewController];
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[highScoreVC presentModalViewController:leaderboardController animated: YES];
}
hope this helps anyone that gets stuck with same problem