Convert NSArray to NSMutable to remove string dynamically - ios

I have a code that I modified to pull data from an external JSON file. There are two NSArrays. One for the image and one for color. Then, when a particular array is pressed it opens a webviewcontroller. I got it to work perfectly. Here is the problem. I want to be able to modify the JSON anytime I want externally and have the app update the information but since the NSArray information is hardcoded I don't know how to remove an array if I remove an objectforkey from the JSON. Any help would be appreciated.
The code to call the images and colors is:
- (IBAction)onclick:(id)sender {
NSArray *images = #[
[UIImage imageNamed:[NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"PhoneUrl"]]],
[UIImage imageNamed:[NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"TextUrl"]]],
[UIImage imageNamed:[NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"MailUrl"]]]
];
NSArray *colors = #[
[UIColor [NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"PhoneColor"]],
[UIColor [NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"TextColor"]]],
[UIColor [NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"MailColor"]]],
];
Sidebar *callout = [[Sidebar alloc] initWithImages:images borderColors:colors];
callout.delegate = self;
[callout show];
}
Then when pressed it calls the following:
- (void)sidebar:(Sidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
self.webViewController = [[PBWebViewController alloc] init];
PBSafariActivity *activity = [[PBSafariActivity alloc] init];
self.webViewController.applicationActivities = #[activity];
self.webViewController.excludedActivityTypes = #[UIActivityTypeMail, UIActivityTypeMessage];
NSLog(#"Tapped item at index %lu",(unsigned long)index);
if (index == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[dataDictionary objectForKey:#"PhoneWeb"]]];
[sidebar dismissAnimated:YES completion:nil];
}
if (index == 1) {
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 = #[[dataDictionary objectForKey:#"TextWeb"]];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[[messageController navigationBar] setTintColor:[UIColor whiteColor]];
[self presentViewController:messageController animated:YES completion:nil];
[sidebar dismissAnimated:YES completion:nil];
}
if (index == 2) {
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
[[mailer navigationBar] setTintColor:[UIColor whiteColor]];
mailer.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:[dataDictionary objectForKey:#"MailWeb"], nil];
[mailer setToRecipients:toRecipients];
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
[sidebar dismissAnimated:YES completion:nil];
}

Related

Send Image with text message

I want to send an image with my text Message. I have used MFMessageComposeViewController. This is the code i have done:
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
NSArray *recipents = #[[arr_promoterDetaildata valueForKey:#"phone_number"], #"72345524"];
UIImage *img = [UIImage imageNamed:#"ic_dummy_img"];
NSData *imgData = UIImagePNGRepresentation(img);
BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:#"image.png"];
NSString *message = [NSString stringWithFormat:#"Sending SMS"];
[messageController setRecipients:recipents];
[messageController setBody:message];
if (didAttachImage)
{
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];
}
else
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Failed to attach image"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[warningAlert show];
return;
}
I have tried so many method’s but it is not attaching image in my message screen. Can anyone help?

How to send the SMS using number in an array?

I have stored the contact numbers in an array and then passed this array to message controller like the below code and printed the value of controller.recipients and its showing null.
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
NSArray *arr = [NSArray arrayWithArray:selContacts];
controller.recipients = arr;
NSLog(#"received:- %#",controller.recipients);
controller.messageComposeDelegate = self;
controller.body =#"https://itunes.apple.com/in/app/Click Here to Download!";
if([MFMessageComposeViewController canSendText])
{
[self presentModalViewController:controller animated:YES];
}
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 = #[#"+919999999999"];
NSString *message = #"Enter message here!";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];

MFMailComposeViewController for Two different labels

My problem is i have a view with a label, wherein, the data on label is coming from web service and on tapping it mail box should appear.In a nutshell it is a mailLabel.
Similarly on the same view i have a custom cell which too has another mail label and the same thing should happen,but the mail address will be different and dynamic.
Q1) do i need to include only one method of mail for this to handle.
Q2) If yes then how and if no then what is the procedure.
i have used a second method for this and called this in cellForRow like
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITapGestureRecognizer *mgmtMail1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(mail1LblTappedForCC:)];
[cell.managementMemberEmail addGestureRecognizer:mgmtMail1LblGesture];
and method.
- (void)mail1LblTappedForCC:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#""];
NSArray *toRecipients = [NSArray arrayWithObjects:objCCforManagement.managementMemberEmail.text, nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"";
[mailer setMessageBody:emailBody isHTML:NO];
mailer.navigationBar.barStyle = UIBarStyleBlackOpaque;
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
where
objCCforManagement is the object of custom class.
How your recognizer will get the to recipient array from
NSArray *toRecipients = [NSArray arrayWithObjects:objCCforManagement.managementMemberEmail.text, nil];
Use recognizer.view to get your label text or get value from objCCforManagement on the basis of label.text. Or particular tag set to label like label.tag=cellRowIndex etc in cellForRow method
Code ----
cell.managementMemberEmail.tag=indexPath.row;
Your mail1LblTappedForCC method is unable to find which row value or objCCforManagement is to be inserted as recipient. thats why it is showing blank.
Get your email on the basis of row tag by setting it to label.
- (void)mail1LblTappedForCC:(UITapGestureRecognizer*)recognizer
{
if ([MFMailComposeViewController canSendMail])
{
UILabel *labelOnWhichItisClicked=(UILabel*)recognizer.view;
CustomCellForExhibitorDetailVC *cell=(CustomCellForExhibitorDetailVC*)[managementTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:labelOnWhichItisClicked.tag inSection:0]];
NSLog(#"mail to is == %#",cell.managementMemberEmail.text);
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#""];
NSArray *toRecipients =[NSArray arrayWithObjects:cell.managementMemberEmail.text,nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"";
[mailer setMessageBody:emailBody isHTML:NO];
mailer.navigationBar.barStyle = UIBarStyleBlackOpaque;
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}

IOS flicker in SDK6.1 but not in 5.X or earlier

I updated my app which was created one year later for SDK 5.X, but now, I get a terrible problem.In the app, using MBProgressHUD to download files from the server, and show an UIAlerView when it finished. but, thus, the view flicker, Someone saied that the UIAlertView should disappeared on the main thread, my code is like this :
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithWindow:[[WNMAppDelegate appDelegate] window]];
hud.labelText = #"Please wait...";
[[[WNMAppDelegate appDelegate] window] addSubview:hud];
[hud showAnimated:YES whileExecutingBlock:^{
[self progressHudMethodForCheckIn:dic];
} completionBlock:^{
[hud removeFromSuperview];
[hud release];
if ([[dic allKeys] count])
{
NSString *key = [[dic allKeys] objectAtIndex:0];
[self alertMessage:[dic objectForKey:key] withTitle:key];
}
else
{
[self alertMessage:#"Succeed sign in" withTitle:#"Nice"];
}
}];
[dic release];
- (void)alertMessage:(NSString *)message withTitle:(NSString *)title{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:(NSString *)message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
can someone help me? Thank you.

What should i do, when user cant send message to twitter

I got app, which can send twits.
I do it in this way:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"])
[tweet addImage:dream.image];
NSString *twitMsg = [dreamField.text stringByAppendingString:#" send via Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
//can't tweet!
}
}
What should i do when [TWTweetComposeViewController canSendTweet] is equal to NO ? And when it is equal to NO ?
That is full solution code:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"]) {[tweet addImage:dream.image];}
NSString *twitMsg = [dreamField.text stringByAppendingString:#" #Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}

Resources