Get mails from iphone settings - objective-c

there any way to get my personal email accounts created in the iphone settings ??
I am making an application to send mail and would like to select one of the email accounts I have on my iPhone to send and then select the destianatorios of my agenda.
Thanks

I'm not exactly sure what you're trying to do, but iOS offers several ways to display an email composition view controller, as well as methods to access the contacts a user has saved on his /her iDevice.
To display a mail composition view, make a weak link to the MessageUI.framework in your project (a weak link is preferred since the MessageUI.framework is not available on very old iOS versions), then do something like this:
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
if (mailClass != nil) {
// MessageUI Library is available. Presenting modal mail composer view.
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:#"This is the subject of the email"];
[mailViewController setMessageBody:#"This is the body of the email." isHTML:NO];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
} else {
// MessageUI Library not available. Opening mail.app using a URL scheme.
// Note that this URL scheme only works on iOS3 and below, and seems to only accept a
// limited number of characters. For this reason, we only attach the URL.
NSString *mailBody = #"This is the body of the email."
NSString *mailSchemeURL = [NSString stringWithFormat:#"mailto:?body=%#", mailBody];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[mailSchemeURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
If you want to access contacts on the iDevice, link AddressBook.framework into your project. You can access the values on the device by following the instructions in Apple's programming guide. For example, you can get an array of all contacts like so:
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *contacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
I expect you can instantiate a mail composition view with a specific contact by using a combination of the above. Hope this helps!

Related

iOS Facebook Share with Link, Photo and Description in the same share dialog

After the iOS 11 relase, the SLComposeViewController is depraceted/not allowed sharing. So iOS developers have to use native Facebook and Twitter SDK to share content. And my problems is raising from this point.
I have been developing a new app which is needed facebook sharing with link, photo and description. i have done separately sharing with photo or link with native FBSDK. But i want to ask you, anyone know how can i use photo and link and description in the same Facebook Dialog. Because in my scenario, i have to share discount detail with discounting shop web site(https://emregurses.com/....../shoes), and discount foto(shoes or bag) and the detail text(Hurry up, you can buy until the midnight)
You can see below codes which i use to share separately.
Photo Share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
shareButton = [[FBSDKShareButton alloc] init];
if (shareImage) {
FBSDKSharePhoto *sharePhoto = [[FBSDKSharePhoto alloc] init];
sharePhoto.caption = facebookTitle;
sharePhoto.image = shareImage;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[sharePhoto];
}
shareButton.shareContent = content;
[shareButton sendActionsForControlEvents: UIControlEventTouchUpInside];
Link Share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
shareButton = [[FBSDKShareButton alloc] init];
if (facebookUrl) {
content.contentURL = [NSURL URLWithString:facebookUrl];
}else{
content.contentURL = [NSURL URLWithString:#"https://fastpay.com.tr/"];
}
shareButton.shareContent = content;
[shareButton sendActionsForControlEvents: UIControlEventTouchUpInside];
But i want to share all of them in the same FBShare dialog as the before SLComposeViewController. Also imageURL property is deprecated the new SDK.
#property (nonatomic, readonly) NSURL *imageURL
DEPRECATED_MSG_ATTRIBUTE("`imageURL` is deprecated from Graph API 2.9");
You can not share predefined text via facebook share.this is the limitation by facebook you can read more here
Use of the iOS share sheet is subject to Facebook Platform Policy,
including section 2.3 which states that apps may not pre-fill in the
context of the share sheet. This means apps may not pre-fill the share
sheet's initialText field with content that wasn't entered by the user
of the app.

How to set email subject from dataDetectorTypeLink?

In the text of a UITextView, I have an email address, and the dataDetectorType is set to dataDetectorTypeLink. Is there any way to set the subject line of an email with this configuration? I know how to set the subject line of an email using an MFMailComposeController, but is there a way to combine that with dataDetectorType?
EDIT: Here's my (re)definition of `openURL:(NSURL *)url in my app delegate:
-(void)openURL:(NSURL *)url
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"feedback on Gay Haiku"];
[self presentViewController:mailer animated:YES completion:NULL];
}
But I get an error No visible #interface for AppDelegate declares the selectorpresentViewController:animated:`.
Did you try appending ?subject= to the link?
#"mailto:webmaster#site.com?subject=Web Site Extraordinaire"
I just realize could use that only if you switched to a UIWebView... Is that an option?
EDIT:
The other way is to subclass UIApplication and override openURL:. This is described here.
Since this seems to be fixed text that you control, you can add a NSLinkAttributeName attribute to the NSAttributedString at the range of your email address instead of enabling automatic link detection. This will let you specify the full URL that you want the system to open when the link is tapped. Then you can use Mundi's suggestion (include subject= in the URL) to set the subject of the email.

How to specify the app name user was using to post - (via app name) using SDK 3.1

Using the new Facebook SDK 3.1 and iOS 6 there are 2 (actually 3) ways to post.
(Seems the new trend is to have more options to make it more simple??) OMG!!
Here is one:
SLComposeViewController *fbPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbPost addURL:[NSURL URLWithString:href]];
[self presentViewController:fbPost animated:YES completion:nil];
And this is another way using native dialogs:
[FBNativeDialogs presentShareDialogModallyFrom:self
initialText: nil
image: nil
url: [NSURL URLWithString:href]
handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
}
else
{
switch (result) {
case FBNativeDialogResultSucceeded:
break;
case FBNativeDialogResultCancelled:
break;
case FBNativeDialogResultError:
break;
}
}
}];
We, developers, think this is cool because we give a nice functionality to the user and also because our app name appears in the post and that can make some promotion of the app.
The funny thing is that latest implementations are not allowing to specify the app name was posting, the name appears after 'via'.
I tried aswell using SLRequest:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *fbType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
(options)[#"ACFacebookAppIdKey"] = kFacebookAppID;
(options)[#"ACFacebookPermissionsKey"] = #[#"publish_stream"];
(options)[#"ACFacebookAudienceKey"] = ACFacebookAudienceFriends;
[store requestAccessToAccountsWithType:fbType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *fbAccounts = [store accountsWithAccountType:fbType];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
(params)[#"link"] = href;
// (params)[#"picture"] = picture;
// (params)[#"name"] = name;
(params)[#"actions"] = #"{\"name\": \"Go Gabi\", \"link\": \"http://www.gogogabi.com\"}";
//Set twitter API call
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:#"https://www.facebook.com/dialog/feed"] parameters:params];
//Set account
[postRequest setAccount: [fbAccounts lastObject]];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if(error)
{
NSLog(#"%#", error.description);
}
else
{
NSLog(#"%#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}
}];
} else {
}
}];
Unfortunatelly to share that name is not so trivial anymore, I wonder why and who was designing the new implementation...
I would appreciate to get some help on that, thanks in advance.
I try to make my questions funny because is soo boring spend time in so trivial topics...
When you use the SLComposeViewController, it's actually the system presenting to you their controller, and it's the user who sends using the post button. Therefore on Facebook it appears as "via iOS".
There's no way to change that.
Using the Facebook SDK 3.1, under the hood it is also using the iOS 6 native integration, so when you're calling the FBNativeDialogs, on iOS 6, it's using SLComposeViewController.
Facebook continued to develop their SDK because they provide a couple of nice modules to use "out of the box" - this includes friends list selector etc... But I believe the biggest reason for Facebook to continue supporting their SDK it for backward compatibility. Under the hood if you're not on iOS 6, it falls back to it's library, and if you are on iOS 6, it uses the system integration.
Facebook is a big thing, and now it's natively available a lot of developers will be using it, just like Twitter's integration last year. The problem of course is at that point the developer has the option to drop older iOS support, or... have a lot of duplicate code, in the sense that they will check for SLComposeViewController and if it's not available (iOS 5) then use the old Facebook SDK... You can imagine how this would become very messy very quickly.
So, the Facebook SDK (3.1) is using iOS system Facebook integration if available, or if not, it's own. In a nutshell, unless you really want the Facebook SDK goodies (friend picket to name one), and you're not planning on supporting iOS < 6 then you don't need to worry about their SDK, just use the Social framework.
So, back to your question, there are 3 ways to post to Facebook ? Actually taking into consideration what I mentioned, there are 2 ways in iOS 6: SLComposeViewController or, SLRequest. On older iOS versions, only 1: Facebook SDK.
Since the SLComposeViewController is owned by the system, not your app, it will always share as "via iOS".
On the other hand SLRequest will show your apps name. When you specify an account for your SLRequest, that account was acquired via the ACAccountStore as a result of passing in some options including ACFacebookAppIdKey, which will be used to determine your Facebook apps name to post onto the users feed as part of the post.
Hope this helps.

Detect if NSString contains a URL and generate a "link" to open inside the app a Safari View

I have am reading a twitter feed in my iPhone application and can do it correctly, but I'd like to evolve it in a way to detect if the whole NSString contains any URL or URLs and create a "link" that will open a UIWebView within the same application.
Can you guide me on how to perform this task?
-(void) setTextTwitter:(NSString *)text WithDate:(NSString*)date
{
[text retain];
[textTwitter release], textTwitter = nil;
textTwitter = text;
[date retain];
[dateTwitter release], dateTwitter = nil;
dateTwitter = date;
[self setNeedsDisplay];
}
Check out Craig Hockenberry's IFTweetLabel, which can be found here.
Or you can use the label provided by Three20 library, which can be found here.
Or the simplest solution: use UIWebView with dataDetectorTypes set to UIDataDetectorTypeLink.
Cheers, Paul

How to escape characters in href=mailto (iPhone)

I want to create a link on a UIWebView that emails content to the user. A simple example is:
<a href="mailto:zippy#example.com?subject=Sarcasm&body=I ยป
<b>love</b> <html> mail!">Hi!</a>
Which creates a message that looks like this:
-- begin message ---
To: zippy#example.com
Subject: Sarcasm
I love mail!
-- end message --
I need something more elaborate. The subject will contain multiple words with spaces. The body will contain HTML, list (<ul>) and hyperlinks with quotes in their href. How do I create something like that?
Here's an example:
subject= "This is only a test"
body= "This is the body part. Here's a list of links:
<ul>
<li>abc.com</li>
<li>xyz.com</li>
</ul>
The end."
Also, why does the simulator do anything when clicking a mailto link?
Fields are URL-encoded (in Cocoa you can use stringByAddingPercentEscapesUsingEncoding: for that).
4thspace mentioned that Mail.app does allow HTML. This is against the
mailto RFC2368, which clearly says that body is supposed to be text/plain.
The simulator doesn't have Mail.app, as you can see from the home screen of it, so it has nothing to open when it encounters a mailto link.
As far as I know though, there is no way to use mailto: to send an html formatted email.
You will need to the MessageUI.framework reference to your project.
Add the following to your .h file
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
Add the delegate <MFMailComposeViewControllerDelegate>
Create a couple methods similar to the following in your .m file.
-(IBAction)checkCanSendMail:(id)sender{
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
if (mailClass != nil) {
if ([mailClass canSendMail]) {
[self displayComposerSheet];
}
else {
//Display alert for not compatible. Need iPhone OS 3.0 or greater. Or implement alternative method of sending email.
}
}
else {
//Display alert for not compatible. Need iPhone OS 3.0 or greater. Or implement alternative method of sending email.
}
}
-(void)displayComposerSheet {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"Email Subject"];
//Set our to address, cc and bcc
NSArray *toRecipients = [NSArray arrayWithObject:#"primary#domain.com"];
//NSArray *ccRecipients = [NSArray arrayWithObjects:#"first#domain.com",#"second#domain.com",nil];
//NSArray *bccRecipients = [NSArray arrayWithObjects:#"first#domain.com",#"second#domain.com",nil];
[mailer setToRecipients:toRecipients];
//[mailer setCcRecipients:ccRecipients];
//[mailer setBccRecipients:bccRecipients];
NSString *emailBody = #"\
<html><head>\
</head><body>\
This is some HTML text\
</body></html>";
[mailer setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
Apple sample code with more instructions available at: http://developer.apple.com/iphone/library/samplecode/MailComposer/
I know this doesn't use the webView but it does allow you to create HTML emails from within your application.