I am using MFMailcomposerViewController in my App. Everything is working fine, except that I am in need to Have the no. of recipients and the list of recipients the user is sending to.
Any help or solution regarding this issue..
I dont there is a standard way to do this, the delegate method mailComposeController:didFinishWithResult:error: gives you a reference to the composer view controller after it has been dismissed, but there are no accessors on MFMailComposeViewController which you could use to get the recipient count
A workaround would be to examine the subviews of the view controller, find the text field which was used to hold the recipients and get the text: see here
Finally I got the Answer and wanted to share it... I took a great help from [blog]: http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html
for (int x=0; x<[emailArray count]-1; x++) {
NSLog(#"%d). %#",x+1,[emailArray objectAtIndex:x]);
NSString *element = [emailArray objectAtIndex:x];
NSArray *arr = [element componentsSeparatedByString:#" & "];
if ([arr count]==1) {
++emailCount;
}
else{
int more = [[[arr objectAtIndex:1] substringToIndex:1] intValue];
emailCount+=(more+1);
}
}
- (NSString *)findEmailAddresses:(UIView *)view depth:(NSInteger)count
{
NSString *eAddress = nil;
if (!view)
return eAddress;
NSMutableString *tabString = [NSMutableString stringWithCapacity:count];
for (int i = 0; i < count; i++)
[tabString appendString:#"-- "];
NSLog(#"%#%#", tabString, view);
if ([view isKindOfClass:[UITextField class]])
{
// MAGIC: debugger shows email address(es) in first textField
// but only if it's about max 35 characters
if (((UITextField *)view).text)
{
eAddress = [NSString stringWithString:((UITextField *)view).text];
NSLog(#"FOUND UITextField: %#", eAddress ? eAddress : #"");
[emailArray addObject:eAddress];
}
}
NSArray *subviews = [view subviews];
if (subviews) {
for (UIView *view in subviews)
{
NSString *s = [self findEmailAddresses:view depth:count+1];
if (s) eAddress = s;
}
}
return eAddress;
}
There is no way to do this as of iOS 6 as mail composition is now done through an XPC service call to a remote process (MailCompositionService). There is a great explanation here: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/. The lowest level in the view hierarchy is now an _UIRemoteView which interfaces to the remote process. The code from the blog post at http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html will now alway return nil.
Related
Hi i am developing a app where when i click contacts it goes to ABpeoplePicekrNavigationcontroller and display all contacts in the form of list in the table.But i want to select all contacts so that i want to perform some action.So how can i achive this.
I am not sure this is the right question to ask.Actually i am trying to send the contact information to next screen instead of selecting single contact information everytime i want to select whole contact list.So how can i do this??
I thought i show them to show in single cell even though space doesnt fit in single cell.just show them single cell so that selecting one cell which contains all contact information would be better to send..
So can anyone suggest me right way to select all the contacts list rather than selecting one contact..I donno whether we can do this or not??if so how???if not what is the other way??
Here is the below code where i am using for accessing the contact list.
- (IBAction)configureMyContact:(id)sender {
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate = self;
peoplePicker.navigationBar.topItem.title = NSLocalizedString(#"CHOOSE_CONTACT_TITLE", #"Defining my contact title.");
[self presentModalViewController:peoplePicker animated:YES];
[peoplePicker release];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
myContactID = ABRecordGetRecordID(person);
[self refreshMyContactButton];
[self saveMyContactID:myContactID];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier{
return NO;
}
You can get your record using this
- (void)getPersonOutOfAddressBook
{
ABAddressBookRef addressBook = ABAddressBookCreate();
if (addressBook != nil)
{
NSLog(#"Succesful.");
NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSUInteger i = 0;
for (i = 0; i < [allContacts count]; i++)
{
ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);
ABMultiValueRef mobile=ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);
for (int k=0;k<ABMultiValueGetCount(mobile); k++)
{
NSString *mobileNo = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(mobile, k);
}
//email
ABMultiValueRef emails = ABRecordCopyValue(contactPerson, kABPersonEmailProperty);
NSUInteger j = 0;
for (j = 0; j < ABMultiValueGetCount(emails); j++)
{
NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emails, j);
}
}
}
CFRelease(addressBook);
}
i have an UIPickerView and i want it to have 2 columns filled with items from my arrays, but i cant figure out how, there is my arrays:
-(void)fillingStandartWeightArray{
if (!standartWeightArray){
for (int i=25; i<150 ;i++){
NSString *weightString;
weightString = [NSString stringWithFormat:#"%d kg", i];
[standartWeightArray addObject:weightString];
NSLog(#"%#", weightString);
}
}
}
-(void)fillingStandartHeightArray{
if (!standartHeightArray){
for (int i=85; i<250; i++){
NSString *heightString;
heightString = [NSString stringWithFormat:#"%d cm", i];
[standartHeightArray addObject:heightString];
NSLog(#"%#", heightString);
}
}
}
To be more specific i don't know how to "tell" UIPickerView to fill one of it wheel with one array, and other one with other array. I tried this:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (component == 0){
return [standartWeightArray count];
} else {
return [standartHeightArray count];
}
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == 0)
return [standartWeightArray objectAtIndex:row];
else if (component == 1)
return [standartHeightArray objectAtIndex:row];
}
And i did call functions in viewDidLoad sections:
- (void)viewDidLoad
{
[super viewDidLoad];
[self fillingStandartWeightArray];
[self fillingStandartHeightArray];
NSLog(#"%#", standartWeightArray);
}
But that's not working.
Your datasource/delegate methods are perfect.
Take care of following things
1) Allocating standartHeightArray and standartWeightArray objects properly. Allocate array objects as below if you are not doing already.
-(void)fillingStandartWeightArray{
if (!standartWeightArray){
// Allocate the array
standartWeightArray = [NSMutableArray new];
for (int i=25; i<150 ;i++){
NSString *weightString;
weightString = [NSString stringWithFormat:#"%d kg", i];
[standartWeightArray addObject:weightString];
NSLog(#"%#", weightString);
}
}
}
-(void)fillingStandartHeightArray{
if (!standartHeightArray){
// Allocate the array
standartHeightArray = [NSMutableArray new];
for (int i=85; i<250; i++){
NSString *heightString;
heightString = [NSString stringWithFormat:#"%d cm", i];
[standartHeightArray addObject:heightString];
NSLog(#"%#", heightString);
}
}
}
2) Connect the delegate/datasource properties of picker properly. You can do it in interface builder or in code (in viewDidLoad)
Sure looks like you are setting everything up correctly to me.
But make sure you set the UIPickerView delegate and data source to the same object / class (ViewController?) where your PickerView data source methods live.
You can set this either in Xcode's Interface Builder, or at "viewDidLoad:" time programmatically (if you have your picker view set to an IBOutlet).
I am new to iphone development. I am developing one iphone application like as sms collection from json parsing in that application having
first category list like as funny sms, love sms in UITableview
when click love sms then i get list love sms in uitablview ....after click particular love sms then i display that particular sms in view ...but my problem is when click back option from love sms to main category it's reponse slow
my back button code is
-(IBAction)btnBackClicked:(id)sender
{
btnAddFav.hidden = FALSE;
btnFavList.hidden = FALSE;
[self startActivityIndicator1];
int Type;
indexId--;
if(indexId < 0)
indexId = 0;
NSMutableDictionary *tempDict1;
for(int i=0;i<[test.JsonPageList count];i++)
{
tempDict1 = [[NSMutableDictionary alloc]init];
tempDict1 = (NSMutableDictionary *)[test.JsonPageList objectAtIndex:i];
if (indexId == 0)
{
tempDict1 = (NSMutableDictionary *)[test.JsonPageList objectAtIndex:0];
Type = [[tempDict1 valueForKey:#"type"] intValue];
if (Type == 0)
{
// lblTitleofApp.hidden = TRUE;``
btnBack.hidden = TRUE;
NSArray *arr=[[tempDict1 valueForKey:#"desc"] componentsSeparatedByString:#";"];
NSString *subStar = #"|#$:";
NSString *sub=#":$#|";
[test.arrTitle removeAllObjects];
[test.arrnew removeAllObjects];
[test.arrId removeAllObjects];
[test.arrImages removeAllObjects];
for (int i=0; i<[arr count]-1; i++)
{
[test.arrTitle addObject:[[arr objectAtIndex:i] substringToIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])-4]];
[test.arrnew addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])]];
[test.arrId addObject:[[test.arrnew objectAtIndex:i] substringToIndex:NSMaxRange([[test.arrnew objectAtIndex:i] rangeOfString:subStar])-4]];
[test.arrImages addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:subStar])]];
}
}
}
how can get privious main category list fastly from particular category ....when click back button
which concept can i use to solve this problem
sorry for simple & bad english words
please giude me
in your main category xib file put your view into navigation controller it has the automatic back button so you dont need code for the back navigation.drag navigation controller to xib and put your view and/or tableview into it.
I'm trying to refresh my main view in this code. It shows the right sub-view, but it's keeping the other views already shown. I already tried setNeedsDisplay and setNeedsLayout but no success.
Any ideas?
Code:
-(void)setViewsForLecture:(NSString *)date{
int scrollHeight = 0;
[self.view setNeedsDisplay];
FMDatabase* db = [DatabaseManager openDatabase];
NSString *query = [NSString stringWithFormat:#"select * from tbl_lectures where day like \"%%%#%%\" ", date];
FMResultSet *rs= [db executeQuery:query];
//Counts how many lectures
int position = 0;
while ([rs next]) {
NSMutableArray *speakers = [[NSMutableArray alloc] initWithCapacity:30];
NSString *lectureName = [rs stringForColumn:#"lecturename"];
FMResultSet *speakersList = [db executeQuery:#SELECT_SPEAKER_FOR_LECTURE, lectureName];
while ([speakersList next]) {
[speakers addObject:[speakersList stringForColumn:#"speaker"] ];
}
if ([speakers count] % 2 == 0)
{
scrollHeight += [speakers count]*40;
}
else
{
scrollHeight += (1 + ([speakers count] -1)/2)*40;
}
NSLog(#"Csantos: speakers for %#: %i",lectureName, [speakers count]);
UIView *aLecture = [CustomInterface viewForLecture:[rs stringForColumn:#"lecturename"]
onPosition:position
withSpeakers:speakers];
[self.scroll addSubview:aLecture];
[aLecture release];
[speakers release];
scrollHeight += 280;
position++;
}
self.scroll.contentSize = CGSizeMake(300, scrollHeight);
[db release];
}
Regards!
Try calling
[self.view setNeedsDisplay];
at the end of the method, after you've made the changes.
I got it working!
I think I didn't understand exactly how setNeedsDisplay works. In this case, was it supposed to redraw my ScrollView too?
Anyway, here is the code that works now:
-(IBAction)clickOnDate1{
for (UIView *view in [self.scroll subviews]) {
[view removeFromSuperview];
}
NSLog(#"Date1 clicked");
[self setViewsForLecture:#"4"];
}
and thanks PengOne for trying to help!
i'm using uitextview for searching the contact details from address book. i.e., like uisearchbar search the contact details while text edit change in uitextview.
i'm using uitextview if i tap 'a', the list of the contacts from address book will be display in table view
please give me the solution
Finally I got the solution simple coding here it is
//viewDidLoad
NSMutableArray *personArray = [[NSMutableArray alloc] init];
ABRecordRef personRef;
for (int i = 0; i < CFArrayGetCount(allPeople); i++)
{
personRef = (ABRecordID*)CFArrayGetValueAtIndex(allPeople, i);
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(personRef));
#try
{
if (ABRecordCopyValue(person, kABPersonBirthdayProperty))
[personArray addObject: (id)personRef];
}
#catch (NSException * e)
{
}
#finally
{
}
NSString *FirstName = [[[NSString stringWithString:(NSString *)ABRecordCopyValue(personRef, kABPersonFirstNameProperty)]stringByAppendingString:#" "]stringByAppendingString:(NSString *)ABRecordCopyValue(personRef, kABPersonLastNameProperty)];
[arr addObject:FirstName];
}
[arr3 addObjectsFromArray:arr];
}
//textviewdidchange
[arr3 removeAllObjects];
NSInteger counter = 0;
for(NSString *name in arr)
{
NSRange r = [name rangeOfString:txtView.text options:NSCaseInsensitiveSearch];
if(r.location != NSNotFound)
{
[arr3 addObject:name];
}
counter++;
}
[table reloadData];
Thanks for your help