How could i add phonebook contacts to my chat app in ios by using xmpp framework and openfire server? - objective-c

I am new to chat application and making it in objective-c. I wanted to know how could i save all my phonebook contacts as user. i know how to fetch contacts from address book but dont have much idea about xmpp framework and openfire.If anyone could help me.

First you know how to fetch contacts.now every contact you need to add Xmpp Roaster.like below
call this method called at your contact fetching class.
[[self appDelegate] addNewBuddyToMyAccount:tempNumber withNickName:[[tempContactList objectAtIndex:i] fullname]];
//in my terms tempNumber is the phone number that is JID.
in your xmpp class follow below code to add to roster
NSString * buddyNameJID = [NSString stringWithFormat:#"%##serverName",buddyUserID];
XMPPJID *jid = [XMPPJID jidWithString:buddyNameJID];
//if you don't need permission then use below line otherwise comment
[[self xmppRoster] acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];
//here we are adding our contact to our roster then check once in roaster in openfire
[[self xmppRoster] addUser:jid withNickname:nickName];
hope this helps.

Related

Is there a way to send a calendar event via UIActivityViewController?

The title pretty much says it all. What follows is my best guess, but the event just doesn't appear at all.
NSArray *items = #[string, URL, (EKEvent *)[self createCalendarEvent]];
UIActivityViewController* activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
[self presentViewController:activity animated:YES completion:NULL];
Does anyone know of a way to accomplish this? Or do I have to create an ics file and send that?
UIActivityViewController:
The system provides several standard services, such as copying items
to the pasteboard, posting content to social media sites, sending
items via email or SMS, and more.
Apps can also define custom services.
It's not (yet) possible to share an EKEvent-object nor its parent EKCalendarItem as none of the standard services provide a way to interact with this type of activity.
You should indeed create an .ics-file to share your event. It's a bit strange that iOS doesn't convert the object by itself as it do this for strings (into .txt-files).
You could however fill in a request to get this option.

STTwitter: Choosing what Account to Use

I'm using STTwitter to post a message to twitter using the API.
I have two active Twitter profile on my OSX Mavericks in the "Internet Accounts" under systems preferences. One is my personal account, the other is something I'm working on.
I'd like to post a tweet to account #2.
Using STTwitterAPI My code looks like this:
twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
Now, the rest of the code worked but it's using the wrong account (it's not the first account).
I looked through the code and I thought I could use something like this:
twitter = [STTwitterAPI twitterAPIOSWithAccount:(ACAccount *)];
And get my account from the store. Now, is there a way to get an "ACAccount" by handle (I can't find it anywhere) or is there a way to have a pop-up show to select which account to use? STTwitter didn't show this.
I saw in the API code they are returning the 'index 0' of accounts so I thought about creating a new method
twitter = [STTwitterAPI twitterAPIOSWithHandle:(NSString *)];
but not sure if it's the right way to go.
Any help would be appreciated!
You can get the accounts defined in System Preferences like this:
ACAccountType *twitterAccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[_accountStore requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {
if(granted == NO) return;
self.osxAccounts = [_accountStore accountsWithAccountType:twitterAccountType];
}];
Yan can then let the user select the ACAccount instance she wants to use.
See STTwitter OS X demo project for a working example.

Authenticating Dropbox in iOS

I am adding Dropbox support to my iOS application. Using the official Dropbox API and the tutorials online here I have gotten to the point where Dropbox needs to be authenticated. The code below is what is given to Authenticate when a button is pressed:
//MainViewController.m
....
#implementation CryptoMainViewController
.....
#pragma mark - Dropbox
- (void)didPressLink {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] link];
}
}
But no matter how I change the code, where I put it or what button I link it to, nothing will happen. Using breakpoints I've found that the method does in-fact get triggered. I've even put it in an IBAction, but this gives the same result. What am I doing wrong? How can I get my app to authenticate the end-user?
And, once authenticated, How can I save an NSString to the user's Dropbox?
If this is just totally wrong, then where can I go to find resources on how to do this properly?
The whole tutorial, all of the documentation, api, etc. is available here.
I had the same problem; the reason was that I hadn't set the shared Dropbox session, e.g.
DBSession* dbSession = [[[DBSession alloc] initWithAppKey: #"your_app_key"
appSecret: #"your_app_secret"
root: kDBRootAppFolder] autorelease];
[DBSession setSharedSession: dbSession];
Once that was called the link worked fine.
this answer may be late but im guessing that you already linked your app before and want to do so again. The only way you can have the process of linking taking place again is if you run the following code:
[[DBSession sharedSession] unlinkAll];
You can place it in your viewDidLoad. When you then call didPressLink: the app should open up dropbox app(if available), safari or an in app window asking for your permission to access your dropbox. If this does not happen then the problem is somewhere else. Hope this helps
Does your view implement the <DBLoginControllerDelegate> ?
If so, link Dropbox like so:
DBLoginController* controller = [[DBLoginController new] autorelease];
controller.delegate = self;
[controller presentFromController:self];

How to set from in MFMailComposeViewController?

How do I set the from address in the MFMailComposeViewController?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"In app email..."];
[controller setMessageBody:#"To FirstName LastName: " isHTML:NO];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"eamil#somemail.com"]; // (NSString *) [feed valueForKey:#"email"]];
[controller setToRecipients:toRecipients];
There isn't a way to do what you want with the From field. The from address will default to whatever mail account the user has specified as "default" in Settings. Obviously if the user has only one mail account set up then it will be that account.
This is possible since iOS 11.0
Use setPreferredSendingEmailAddress(_:) to define a preferred address which will automatically select a corresponding account if available.
From the documentation:
Sets the preferred email address to use in the From field, if such an address is available.
If the user does not have an account with a preferred address set up, the default account is used instead.
Call this method before you display the mail composition interface only. Do not call it after presenting the interface to the user.
As far as I know, it's not possible. When the mail composer is open, you will be able to fetch the "from" field from the list of e-mails configured in the device, and the user selected default will be initially set.
I know that it would be useful to know the list of available "from" accounts and set the composer with a more appropriate user choice. Probably Apple doesn't want to give the app this possibility. You might open a "radar" with Apple, e.g. adding a special view controller to let the user define a different default address for the specific app, this would be a nice addition to the iOS.
I don't think you can change "from" if you use MFMailComposeViewController in app email in iOS Another workaround, you may use this, a standalone email client, instead. You will have better control of the sender programmatically.

Getting user's default email address in Cocoa

How do I obtain the user's default email address? I need to obtain it for my crash reporter dialog, so the user won't have to fill it out manually.
Never mind, I got it. First, I just have to add AddressBook.framework into my Linked Frameworks. Then, this is the code required:
#import <AddressBook/AddressBook.h>
NSString *theEmailAddressWeWantToObtain = #"";
ABPerson *aPerson = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emails = [aPerson valueForProperty:kABEmailProperty];
if([emails count] > 0)
theEmailAddressWeWantToObtain = [emails valueAtIndex:0];
From "*Address Book Programming Guide for iOS":
Link the Address Book UI and Address Book frameworks to your project.
Important The project will fail to build (with a linker error) if you do not link against both of these framework.
Linking in the Framework without the UI will prevent the sample code from compiling.