how to invite yahoo friends .on button click yahoo login page should be open.
afer login page oen i want send invitaion to my friend .plz suggest how can i do ?
for facebook we use following code but how we can do in yahoo.
-(IBAction)InviteYourFriendsBtnClk:(id)sender
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just smashed friends! Can you beat it?"]
title:#"StopNSwap"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}
friendCache:nil];
}
The easiest way to do this would be sending an email to the person asking to follow your yahoo page.
// From within your active view controller
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self;
[mailCont setSubject:#"Follow us on Yahoo!"];
[mailCont setToRecipients:[NSArray arrayWithObject:#"stkovf#jaydz49.com"]];
[mailCont setMessageBody:#"Follow our apps yahoo page" isHTML:NO];
[self presentModalViewController:mailCont animated:YES];
[mailCont release]; }
// Then implement the delegate method
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES]; }
Related
Is there any way of checking if the user actually presses the send button when using the MFMailComposeViewController class?
Thanks
Use the MFMailComposeViewControllerDelegate (https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewControllerDelegate_protocol/Reference/Reference.html)
-(void)sendMail
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
[mailer setMailComposeDelegate:self];
//do the rest of the mail composing
...
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
//don't forget to dismiss the controller
[controller dismissModalViewControllerAnimated:YES];
if(result == MFMailComposeResultSent)
{
//the user sent the mail
}
}
I have a home page with table and one button, with pressing my button I will load the qrCode reader view, I want to hide my qrCode view after scan the barcode,
would you please give me some hint what is the best way to do this? NSNOtification or ...
and how?
Thanks in advance!
Here is my qr view code that scans the code:
- (void) readerView:(ZBarReaderView *)readerView didReadSymbols: (ZBarSymbolSet *)symbols
fromImage:(UIImage *)image
{
ZBarSymbol * s = nil;
for (s in symbols)
{
image_view.image = image;
// here I will go to httpReq class for addStamp method
[[HttpReq sharedHttp] setCode:s.data];
[[HttpReq sharedHttp] addStamp];
}
}
Here is my addStamp method that I have to hide the view in this method:
-(void) addStamp
{
// My code was here for connect to api
NSError *jsonError;
NSDictionary* dic = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&jsonError];
if(jsonError != nil)
{
return;
}
// I want to do it here when I have a success or not
BOOL success = [[dic objectForKey:#"success"] boolValue];
if(success){
[self addStampInDB:[[dic objectForKey:#"cardId"] intValue]];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:[dic
objectForKey:#"error"]
delegate:nil
cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert performSelectorOnMainThread:#selector(show) withObject:nil
waitUntilDone:NO];
}
}];
}
Hiding a view in Objective-C is quite simple:
[theView setHidden:YES];
When the addStamp method is called you could invoke a method that is defined in the first class using performSelector or you could follow protocol and delegate mechanism to keep it neat.
I'm trying to Implement chat module in my app. I am successfully done with Login and Register process from Simple Chat Demo into my app. It also returns user array of offline and online users.
Now after successfully log in I am getting below log :-
error:
2012-12-07 14:50:07.056 App[5324:790b] QBChatService/xmppStreamDidConnect
2012-12-07 14:50:08.285 App[5324:790f] QBChatService/xmppStreamDidAuthenticate
2012-12-07 14:51:08.291 App[5324:711f] QBChatService/xmppStreamDidDisconnect, error=Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0xb982330 {NSLocalizedDescription=Socket closed by remote peer}
And I'm not able to receive chat messages into my app.
Any suggestions ?
Edit :-
In my app, when login is done I am sending the login request to QuickBlox API
if(loginDone)
{
NSString *userName = [_textUsername.text stringByReplacingOccurrencesOfString:#"#" withString:#"_"];
NSString *userPass = [_textPassword.text stringByReplacingOccurrencesOfString:#"#" withString:#"_"];
// Authenticate user
[QBUsers logInWithUserLogin:userName password:userPass delegate:self context:userPass];
}
#pragma mark -
#pragma mark QBActionStatusDelegate
// QuickBlox API queries delegate
-(void)completedWithResult:(Result *)result context:(void *)contextInfo
{
// QuickBlox User authentication result
if([result isKindOfClass:[QBUUserLogInResult class]])
{
// Success result
if(result.success)
{
QBUUserLogInResult *res = (QBUUserLogInResult *)result;
// save current user
[[DataManager shared] setCurrentUser: res.user];
NSLog(#"%#",res.user);
[[[DataManager shared] currentUser] setPassword:(NSString *)contextInfo];
NSLog(#"%#",res.user);
// Login to Chat
[QBChat instance].delegate = self;
[[QBChat instance] loginWithUser:[[DataManager shared] currentUser]];
// Register as subscriber for Push Notifications
[QBMessages TRegisterSubscriptionWithDelegate:nil];
// send request for getting user's filelist
PagedRequest *pagedRequest = [[PagedRequest alloc] init];
[pagedRequest setPerPage:10];
[QBContent blobsWithPagedRequest:pagedRequest delegate:self];
[pagedRequest release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Errors"
message:[result.errors description]
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
alert.tag = 1;
//[alert show];
[alert release];
[HUD hide:YES];
[self AfterLoginController];
}
}
}
-(void)completedWithResult:(Result *)result
{
if([result isKindOfClass:[QBUUserLogInResult class]]) // QuickBlox User authentication result
{
// Success result
if(result.success)
{
// If we are authenticating through Twitter/Facebook - we use token as user's password for Chat module
[self completedWithResult:result context:[BaseService sharedService].token];
}
}
else if ([result isKindOfClass:[QBCBlobPagedResult class]])
{
// Success result
if(result.success){
QBCBlobPagedResult *res = (QBCBlobPagedResult *)result;
// Save user's filelist
[DataManager shared].fileList = [[res.blobs mutableCopy] autorelease];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app startsendPresenceTimer];
[HUD hide:YES];
[self AfterLoginController];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Errors"
message:[result.errors description]
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
alert.tag = 1;
//[alert show];
[alert release];
[HUD hide:YES];
[self AfterLoginController];
}
}
Now in AppDelegate :-
- (void) startsendPresenceTimer
{
[QBChat instance].delegate = self;
// send presence
if(self.sendPresenceTimer == nil)
{
self.sendPresenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(sendPresence) userInfo:nil
repeats:YES];
}
if (self.requesAllUsersTimer == nil)
{
self.requesAllUsersTimer= [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(updateUsers) userInfo:nil repeats:YES];
}
[self.requesAllUsersTimer fire];
}
// send presence
- (void)sendPresence{
// presence in QuickBlox Chat
[[QBChat instance] sendPresence];
// presence in QuickBlox
[QBUsers userWithExternalID:1 delegate:nil];
}
- (void)updateUsers
{
// Retrieve all users
PagedRequest* request = [[PagedRequest alloc] init];
request.perPage = 100; // 100 users
[QBUsers usersWithPagedRequest:request delegate:self];
[request release];
}
Do you send presence periodically? It need because Chat server must knows is you online or offline.
Look at QuickBlox Chat setup guide, lines
Keep in mind that QuickBlox it's simple XMPP chat, ...
Just write single line
[NSTimer scheduledTimerWithTimeInterval:30 target:[QBChat instance] selector:#selector(sendPresence) userInfo:nil repeats:YES];
Application will send presence every 30 seconds
Here is my .m code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *emailCell = [tableView cellForRowAtIndexPath:indexPath];
if ([emailCell.textLabel.text isEqualToString:#"Contact Developer"]) {
NSLog(#"Email button pressed...");
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"A Message from MobileTuts+"];
NSArray *toRecipients = [NSArray arrayWithObjects:#"fisrtMail#example.com", #"secondMail#example.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"Have you seen the MobileTuts+ web site?";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(#"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(#"Mail not sent.");
break;
}
// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}
}
else {
UIAlertView *emailAlert = [[UIAlertView alloc] initWithTitle:#"Error!"
message:#"Please make sure you have an email address configured in your Mail app."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[emailAlert show];
[emailAlert release];
}
}
}
I have imported everything correctly in .h and .m, but the email won't close... I have tried as suggested on Stack Overflow to fiddle with the mailer.mailComposeDelegate = self; but I am still getting an undeclared identifier error. How do I fix this? Thanks.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
Move this function out of the tableview delegate method. You should learn some basics. You cannot have a method within another method. If you need then you can call the method by [self callingFunctionName];
In you case,
if ([emailCell.textLabel.text isEqualToString:#"Contact Developer"]) {
NSLog(#"Email button pressed...");
[self sendEmail];
}
-(void)sendEmail{
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"A Message from MobileTuts+"];
NSArray *toRecipients = [NSArray arrayWithObjects:#"fisrtMail#example.com", #"secondMail#example.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"Have you seen the MobileTuts+ web site?";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
}
This will open the mail composer. When you send, cancel or save the mail, the delegate function
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
will automatically be called.
i done a sample ipad mail composer application to send a image to another address.so i wrote the following code:
#import <messageUI/MFMailComposeViewController.h>
//to compose mail
-(IBAction)composeMail{
if([self validateImageView]){
[self sendSelectedImage];
}
else{
[self showAlert];
}
}
//to validate image view
-(BOOL)validateImageView{
if(selectedImageView.image){
return YES;
}
else{
return NO;
}
}
//to send selected image
-(void)sendSelectedImage{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
#try {
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello from Triassic!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"shamsudheen#triassicsolutions.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:#"shamsudheen#triassicsolutions.com", #"shamsudheen#triassicsolutions.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:#"shamsudheen#triassicsolutions.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSData *myData = UIImagePNGRepresentation(selectedImageView.image);
[picker addAttachmentData:myData mimeType:#"image/jpeg" fileName:#"rainy"];
// Fill out the email body text
NSString *emailBody = #"It is raining in Trivandrum!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
#catch (NSException * ex) {
NSLog([NSString stringWithFormat:#"%#",ex]);
}
#finally {
[picker release];
}
}
//to show a alert box
-(void)showAlert{
UIAlertView *alertView;
alertView = [[UIAlertView alloc] initWithTitle:#"Please select a image from PhotoAlbums!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:#"Continue", nil];
[alertView show];
[alertView release];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation==UIInterfaceOrientationLandscapeRight || interfaceOrientation==UIInterfaceOrientationLandscapeLeft);
}
#pragma mark -
#pragma mark Dismiss Mail/SMS view controller
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the
// message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
#try {
feedbackMsg.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
feedbackMsg.text = #"Mail sending canceled";
break;
case MFMailComposeResultSaved:
feedbackMsg.text = #"Mail saved";
break;
case MFMailComposeResultSent:
feedbackMsg.text = #"Mail sent";
break;
case MFMailComposeResultFailed:
feedbackMsg.text = #"Mail sending failed";
break;
default:
feedbackMsg.text = #"Mail not sent";
break;
}
}
#catch (NSException * ex) {
NSLog([NSString stringWithFormat:#"%#",ex]);
}
#finally {
[self dismissModalViewControllerAnimated:YES];
}
}
so when compose button clicks it will show a popup with the entered mail address and with all the details.
it showing the result send process is done successfully.but i am not getting any mail to shamsudheen#triassicsolutions.com.may i know what is the mistake i done.can i send a mail through this to another email by entering the popup through the address section.i think the compose method works when popup is loading.then how can i send a mail to address that in entered in the displayed popup.it not working fine ..may i know whats the mistake i done
In Simulator you cannot send the mail because If you want to send a mail to another person first you have to set your maildetails(you have to login to your account) in the account settings in the Device. But that feature is not exists in the Simulator.That's why you cannot send the email from Simulator.