Showing/Decoding received chat message XMPP framework ios - iphone

I am able to send Message to specific Person selected through XMPPframework IOS. I am receiving messages from others sent to me and I can see using NSLog in following method.
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
I have gone through What I want to know is, if any method available in XMPP to directly decode received chat message ? i.e. like If
- [message getChatMessage];
Or we need to implement on our own ? i.e decoding received XML and get requirement element string.
Please share if any one knows.

Well, you can get, for example, the body of the message by doing this:
NSString *body = [[message elementForName:#"body"] stringValue];
The values for other tags can be found like this. XMPP uses XML to structure its data, so the elementForName: and attributeForName: methods should give you the data you need.

Related

Getting user's form data on iOS

I need to have my users fill out a form, and send me the information. Nothing fancy, just their name and email, and they'd be doing it willingly.
I looked into emailing the information to my account, but it seems like you have to pop the MFMailComposeViewController and let the user submit an email -- and I don't want to bother them with that.
I also tried a simple mailto url, like this:
NSString *url = #"mailto:example#example.com?&subject=Greetings from Cupertino!&body=Wish you were here!";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
But it doesn't work on my simulator, or my iPhone, which is 4s with iOS 6.
I also looked into creating a google doc, and have the application send the user's info to its URL, but I'm assuming the result would be similar to the mailto URL?
So is there a good, simple way to do it?
So is there a good, simple way to do it?
Sure -- but not using mail. Use HTTP instead, and POST the data to a web server. If you need to collect the results by mail, you could easily create an e-mail message on the server and send from there, but it seems more likely that you'll just want to add the information to a database directly.
To use HTTP, you'll create a NSURLRequest with the relevant parameters and then send it using NSURLConnection. If you don't feel like digging into the URL loading system that iOS provides, there are a number of wrapper libraries that make it even easier. But for what you want to do, using NSURLConnection directly will be pretty straightforward.
Maybe you should have a look at these links :-
How to send mail from iphone app without showing MFMailComposeViewController?
Send mail without MFMailComposeViewController
Sending Email without using MFMailComposeViewController
MFMailComposer send email without presenting view

Get message body and recipients list from MFMessageComposeViewController

Is there a legal way to get body text and recipients list from MFMessageComposeViewController after SMS was sent(in didFinishWithResult callback delegate)?
I have an application which sends SMS and saves it in history. I'm using MFMessageComposeViewController for sending SMS. This is needed in order to save message correctly to history and perform searches.
I know there is no way to change body and recipients list after controller was shown, i want to get them.
I know there is phone's SMS history - but i need this in history of my application due to specific functionality of application according message body.
There is an official "legal" standard way to do this:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
NSString *sms = controller.body;
Same with controller.recipients...

Characters getting cut off by Mail app when launching from within my app

I'm trying to set up a prefilled email for the user to send through the iphone native Mail application. The body of the email contains a link that the user wants to share.
My problem is that the link is getting cut off by the Mail app but when I print out the string in my app the whole link is there.
Here is a sample link:
http://sample.com/Start.asp?tqnm=xe2nbek92057479&bt=xg&o=100925&c=RB&p=2W7TvRx1
In the mail app the link shows up as:
http://sample.com/Start.asp?tqnm=xe2nbek92057479
I am using the standard code for launching the Mail app:
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSLog(#"Mail String: %#", mailString);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
I've also tried other string encodings but I either get the same result or the body of the email doesn't show up at all.
Any help would be really appreciated. I've been looking for the answer for a while and haven't found anything to even point me in the right direction.
I was able to solve it, I found this function
NSString* encodeToPercentEscapeString(NSString *string) {
return (NSString *)
CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef) string,
NULL,
(CFStringRef) #"!*'();:#&=+$,/?%#[]",
kCFStringEncodingUTF8);
Then I used that to encode the body, which took care of the ampersand case, which Matthias was referring to. Thank you Matthias for pointing me in the right direction.
This is perhaps more a work-around than an answer, but... You might consider using the MessageUI framework to send the mail directly from within your app. You can easily set the body of the mail without any encoding issues and it also a little bit nicer for the user (i.e. does not switch away from your application).
There are plenty of tutorials/code snippets on the web about how to do this. (I wrote this one a while ago Sending Mail from your App). Hope this helps!

Checking SMS sending status iPhone

It's possible to check SMS sending status? e.g.
MFMessageComposeViewController * smsPicker = [[MFMessageComposeViewController alloc] init];
smsPicker.messageComposeDelegate = self;
smsPicker.body = #"Body";
[self presentModalViewController:smsPicker animated:YES];
[smsPicker release];
I don't know why, but the delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result; executing before sending and works if user cancelled SMS.
And I need to know, if SMS sent or failed (e.g. cell network error or something wrong). Thanks for future help!
You can use the result parameter messageComposeViewController:didFinishWithResult: to check the status of the message. Its type is MessageComposeResult:
enum MessageComposeResult {
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
};
Bear in mind that MessageComposeResultSent may only be interpreted as a successful queueing of the message for later sending. The actual send will occur when the device is able to send.
How can I check if device is able to send?
To test whether a device is capable of sending text messages, use MFMessageComposeViewController's canSendText class method. According to the documentation, you should always call this method before attempting to present the message compose view controller.
However, this will not tell you if the device is able to send the message now (in case you asked with this statement in mind: The actual send will occur when the device is able to send).
Unfortunately it does not account for cell network interruptions at the very least. For example when in airplane mode the delegate receives a MessageComposeResultSent!
I have filed a radar for this. Duplicating it may get the issue resolved sooner.

How to get the data from xml file

I have an application which binds a map with user's location, 2 pictures and some text in the xml file and send it to the other user through email.
Now the question is that if the other user who is receiving it, how i should make this xml file parsed in my application so that the receiver can have a sensible look of the data like the map with two tabs (pictures and comments).
The basic question is how i can read the sent xml file at receiver's end.
Thanks,
At the sender's end, create an NSDictionary containing the location, the data of the two UIImages and the NSString. Then, save it as a plist, and send it via email. Then, at the receiver's end, create an NSDictionary with the contents of the file (NSDictionary *dataDict = [[NSDictionary alloc] initWithContentsOfFile:YOUR_FILE];), and then get the objects using the relevant keys that you set for them when you added them to the dictionary.
Hope this helps,
jrtc27