I am new in iOS programming, I know this is too old question but I am confused here about message controller. I want to make a application in which I want to send simple messages.
if I set multiple recipients can any of one can you view all recipients?
if it so,then how can I make a private message for all so that one recipient can't view other recipients?
Here is my code for composing a message for more recipients
- (void)showSMS:(NSString*)file {
if(![MFMessageComposeViewController canSendText]) {
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSArray *recipents = #[#"12345678", #"72345524"];
NSString *message = [NSString stringWithFormat:#"Just sent the %# file to your email. Please check!", file];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self presentViewController:messageController animated:YES completion:nil];
}
There's a setting in Settings -> Messages which disables group messaging, and all recipients will receive the messages separately. Other than that, you can't do it with MFMessageComposeViewController because there's no bcc option. Your could send the messages one at a time though
Related
I want to send the email from my iOS device programtically using iOS.I am using the below code to send the email but i don't know where to enter from field.From which email id the mail will be sent?
Code for Sending email in iOS
// Email Subject
if(![MFMailComposeViewController canSendMail])
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device doesn't support Email!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSString *emailTitle = #"Test Email";
// Email Content
NSString *messageBody = #"iOS programming is so fun!";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:#"support#appcoda.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
Just to add, one other thing you can't do using the built-in MFMailComposeViewController class is to send emails silently, without the full-screen "Compose email" view appearing.
In my app, I resorted to sending the email details (To address, Body text, etc) to my app's WCF web service, and getting that to send the email instead.
And, of course, doing it that way, you can choose which From address you wish to use.
You cannot actually set the From field when using the MFMailComposeViewController. What actually happens is the From field will default to whatever email account the user has specified to be used as the default email account on the device in the settings.
After spending some time looking at similar questions on stack overflow, unfortunately none seemed to resolve my issue.
I'm using a UIActionSheet, when the user clicks send email on the action sheet, the following code is called:
if ([MFMailComposeViewController canSendMail]){
NSString *emailTitle = #"bla bla bla";
// Email Content
NSString *messageBody = #"bla bla bla";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:#"test#test.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
[self.view.window.rootViewController presentViewController:mc animated:YES completion:NULL];
NSLog(#"email view opened");
}
else{
UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"No mail account setup on device" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[anAlert addButtonWithTitle:#"Cancel"];
[anAlert show];
}
MFMailComposeViewController opens on my iPhone in portrait mode, but when opening the app in landscape mode on an iPad, nothing happens. No view pops up, nothing at all.
It shows "email view opened" in the NSLog but nothing else.
Thoughts?
Edit The app is portrait ONLY on iPhone, and any orientation for iPad
EDIT AGAIN
After playing around a bit more, if I assign the code to a button, it works fine, only when selecting email from the action sheet is this problem present
Found the answer, this is it :
dispatch_async(dispatch_get_main_queue(), ^ {
// INSERT EMAIL CODE HERE
});
I am fairly new to jailbreak iOS development and had a question. I am trying to send a message between two processes(MobileSafari to SpringBoard) and am having a problem, the reciever function in SpringBoard is never called! So far in SpringBoard I have this:
-(void)applicationDidFinishLaunching:(id)arg1{
%orig(arg1);
//register for notifications
CPDistributedMessagingCenter *messagingCenter = [CPDistributedMessagingCenter centerNamed:#"com.magnusdevelopment.flow"];
[messagingCenter runServerOnCurrentThread];
[messagingCenter registerForMessageName:#"updateWallpaper" target:self selector:#selector(handleMessageNamed:withUserInfo:)];
[messagingCenter registerForMessageName:#"updateScalingMode" target:self selector:#selector(handleMessageNamed:withUserInfo:)];
[messagingCenter registerForMessageName:#"downloadWallpaper" target:self selector:#selector(handleMessageNamed:withUserInfo:)];
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:#"Yo!" message:#"registered" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[testAlert show];
}
}
%new
-(NSDictionary *)handleMessageNamed:(NSString *)name withUserInfo:(NSDictionary *)userInfo{
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:#"Yo!" message:#"2" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[testAlert show];
if([name isEqualToString:#"updateWallpaper"]){
//get info for wallpaper
NSString *wallpaperImagePath = [userInfo objectForKey:#"WALLPAPER_PATH"];
int option = [[userInfo objectForKey:#"OPTION"] intValue];
BOOL retValue = setWallpaperImage(wallpaperImagePath, option);
//return the dictionary
NSMutableDictionary *replyDict = [[NSMutableDictionary alloc] init];
[replyDict setObject:[NSString stringWithFormat:#"%hhd",retValue] forKey:#"RETURN_VALUE"];
return replyDict;
}else if([name isEqualToString:#"updateScalingMode"]){
//get info from dictionary
int option = [[userInfo objectForKey:#"OPTION"] intValue];
NSString *scalingMode = [userInfo objectForKey:#"SCALING_MODE"];
//set wallpaper scaling mode
setWallpaperScalingMode(scalingMode,option);
}//end if
return nil;
}//end method
and when a button is pressed in MobileSafari I call this code:
NSString *option = [NSString stringWithFormat:#"%i",wallpaperOption];
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys: wallpaperPath, #"WALLPAPER_PATH", option, #"OPTION", nil];
CPDistributedMessagingCenter *messagingCenter = [CPDistributedMessagingCenter centerNamed:#"com.magnusdevelopment.flow"];
[messagingCenter sendMessageAndReceiveReplyName:#"downloadWallpaper" userInfo:infoDict];
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:#"Yo!" message:#"sent" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[testAlert show];
I get the alert "registered" whenever SpringBoard starts up and then when I press the button I get the message "sent". The only thing that isn't called is the function handleMessageNamed:withUserInfo:
Why isn't this working?
Thanks!
Try darwin notifications https://developer.apple.com/library/mac/documentation/corefoundation/Reference/CFNotificationCenterRef/Reference/reference.html It's a public API, shouldn't be hard to find sample code.
If you look at this document entitled "Updating extensions for iOS 7, it looks there are problems using CPDistributedMessagingCenter on iOS 7, but Ryan Petrich has published a library that may help you work around them:
Inter-process communication
CPDistributedMessagingCenter, XPC and other IPC methods built on top
of bootstrap registered mach services don't work; you get deny lookup
in the Xcode console.
Workaround: rpetrich has built a workaround called RocketBootstrap: "One common way processes communicate with each other
on iOS and OS X is through a messaging system called mach ports. Each
port is a channel that can either receive or send messages. There is a
central registration system for these ports called bootstrap, where
ports can be registered and accessed by a service name assigned to
them. Recent versions of iOS restrict which names a process can
access—MobileMail, MobileSafari and App Store apps are only allowed to
access a very specific set of services that come with iOS.
RocketBootstrap adds a secondary lookup service that doesn't restrict
which processes can access which services."
Hello friends I have used MFMessageComposeViewController to send message for specific mobile number. For that i have used following code:
if(phoneNumber)
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = #"Hello";
controller.recipients = [NSArray arrayWithObjects:#"+9876543210", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
Here in recipients array i had set one mobile number. Can i set their name in place of the number? Due to privacy reason i don't want to show the mobile number there.
Is it possible? If yes then how can we implement that.
Thanks in advance.
I'm building an app that allows the user to export en import data files and send them by e-mail.
So I've created a data file type with extension ".myAppExtension".
At first time everythings goes well. I can't export and send an e-mail. And when I open the e-mail, the method does work.
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (url != nil && [url isFileURL]) {
NSLog(#"%#",url);
NSLog(#"%#",[url pathExtension]);
if([[[url pathExtension] lowercaseString] isEqualToString:[#"myAppExtension" lowercaseString]]){
//Deal with received file
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Export ok" message:[NSString stringWithFormat:#"This file has been added : %#",[url lastPathComponent]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil,nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Export failed" message:[NSString stringWithFormat:#"This extention is not supported : %#",[url pathExtension]] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil,nil];
[alert show];
}
}
return YES;
}
My issue is that when I want to export an other type of file with extension "otherExtension". I did not create data type for this extension in my app.
So I export and send an e-mail with this second type of file. The file name showed in e-mail "file.otherExtension". But, this is the issue, when I tap this mail attachement the e-mail app offers me to open it in my application. That's not what I want and, as I said, I did not create the data type for "otherExtension".
Edit : This is how I created the file type in myApp-info.plist :
If someone is interested, the issue were from the send e-mail fonction.
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init] ;
[picker setSubject:mailSubject];
[picker addAttachmentData:codedData mimeType:#"application/myApp" fileName:[filePath lastPathComponent]];
[picker setToRecipients:[NSArray array]];
[picker setMessageBody:mailBody isHTML:NO];
[picker setMailComposeDelegate:self];
[currentMainViewController presentViewController:picker animated:YES completion:nil];
By adding the mime type to mail attachment the receiving application was using it to read the file. Replacing the mime type by "nil" solved my issue.
[picker addAttachmentData:codedData mimeType:nil fileName:[filePath lastPathComponent]];