I'm getting values from database and assinging those values to NSMuatbleArray. Then i have sharing array of values into mail. How to share the values with setMessgaeBody:
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
sk_code = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(statement, 4)];
NSLog(#"sk_code %#",sk_code);
[product_sku_array addObject:sk_code];
// To address
NSArray *toRecipents = [NSArray arrayWithObject:#"test#gmail.com"];
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
// mailController.mailComposeDelegate = self;
[mailController setSubject:#"Test"];
[mailController setMessageBody:product_sku_array isHTML:NO];
[mailController setToRecipients:toRecipents];
[self presentViewController:mailController animated:YES completion:nil];
}
NSLog:
product_sku_array (
123
)
sk_code test1
product_sku_array (
123,
test1
)
temp inside is 123,test1
Initialise your array properly and then use
[mailController setMessageBody:[product_sku_array componentsJoinedByString:#","] isHTML:NO];
[mailController setMessageBody:] accepts string parameter, so,
take the NSMutableString and append every array object into your single string
like
string = [string appendString:[NSString stringWithFormat:"%#", [array
objectAtIndex:i]]];
then set this string to message body, like,
[mailController setMessageBody:string isHTML:NO];
Related
I am sending SQLite(Coredata sqlite file) file via email but found empty data in all tables in the received mail.
I am using below code:
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:subject];
[mc setMessageBody:body isHTML:FALSE];
if (attachmentData) {
[mc addAttachmentData:attachmentData mimeType:fileMimeType fileName:fileName];
}
if (!recipients || recipients.count == 0) {
recipients = #[];
}
[mc setToRecipients:recipients];
[presentedViewController presentViewController:mc animated:YES completion:nil];
Here, fileMimeType = "application/x-sqlite3" and fileName: xyz.sqlite
Found the same question here, but with no solution. Any idea how to do that?
As I indicated in comments, iOS uses SQLite’s WAL mode by default, so you need to include the WAL file as an attachment.
Are you sure that you attachmentData isn't nil?
How large is your attachmentData?
How are you constructing your data from the sqlite file?
This test code seemed to work fine for me with sending a simple sample database:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self sendSampleMailWithDbAttached];
}
- (void)sendSampleMailWithDbAttached {
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:#"Message Subject"];
[mc setMessageBody:#"Message Body" isHTML:NO];
NSString *sqliteFilePath = [self createTestDb];
NSData *attachmentData = [NSData dataWithContentsOfFile:sqliteFilePath];
if (attachmentData) {
[mc addAttachmentData:attachmentData mimeType:#"application/x-sqlite3" fileName:#"xyz.sqlite"];
}
[mc setToRecipients:#[#"fake#email.com"]];
[self presentViewController:mc animated:YES completion:nil];
}
- (NSString *)createTestDb {
NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingPathComponent: #"xyz.sqlite"];
sqlite3 *db;
if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
NSString *query = #"CREATE TABLE IF NOT EXISTS test(abc TEXT, def TEXT);";
if (sqlite3_exec(db, [query UTF8String], NULL, NULL, NULL) == SQLITE_OK) {
query = #"INSERT INTO test(abc, def) VALUES('ABC', '123');";
}
sqlite3_close(db);
}
return databasePath;
}
I want to filter data from NSMutableArray that contains NSArray as an object. Below is code that I have used for set object-
[self setFieldType];
NSMutableArray *kirtanList=[[NSMutableArray alloc] init];
NSString *sql = [NSString stringWithFormat:#"SELECT Id,%# FROM Kirtan_list where Title_Eng like '%#%%' or Title_Eng like '%%%#%%' order by Title_Eng", titleField, text,text];
sqlite3_stmt * statement;
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK)
{
while(sqlite3_step(statement) == SQLITE_ROW)
{
char *field1 = (char *) sqlite3_column_text(statement, 0);
NSString *field1Str = [[NSString alloc] initWithUTF8String:field1];
char *field2 = (char *) sqlite3_column_text(statement, 1);
NSString *field2Str = [[NSString alloc] initWithUTF8String:field2];
NSArray *data=[NSArray arrayWithObjects:[NSString stringWithFormat:#"%#",field1Str],[NSString stringWithFormat:#"%#",field2Str],nil ];
[kirtanList addObject:data];
}
}else{
NSLog(#"Filtered row error ");
}
help me for filter data.
Solve this by this code
NSPredicate * predicate = [NSPredicate predicateWithFormat:#"ANY SELF BEGINSWITH[cd] %#",_textField.text];
NSMutableArray *marrObject=[[NSMutableArray alloc] init]; //Declare Array Object
//Loop for find array objects
for (id arrObject in marrObject) {
if ([arrObject isKindOfClass:[NSArray class]]) {
NSLog(#"It's Array Object");
}
}
I am working with the SQLite i am able to create the table and alter table but after adding columns to the table, data is not fetching.
Up to now my implementation inserting table values like below
NSString *sqlString=[NSString stringWithFormat:#"insert into %#(toid,fromid,msg,timedate,left,messageID,chatStatus) values('%#','%#','%#','%#',%d,'%#','%#')",tableName,userid,friendid,message,timedate,(int)leftright,messageID,chatStatus];
below i am fetching data from table
-(NSMutableArray *)AllRowFromTableName:(NSString *)tableName withUserID:(NSString *)userid withFriendID:(NSString *)friendid
{
NSMutableArray *array=[[NSMutableArray alloc] init];
NSString *sqlString=[NSString stringWithFormat:#"select *from chatTable where toid='%#' and fromid='%#'",userid,friendid];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db, [sqlString UTF8String], -1, &statement, nil)==SQLITE_OK) {
while (sqlite3_step(statement)==SQLITE_ROW) {
ChatHistorySkeleton *tempSkeleton=[[ChatHistorySkeleton alloc] init];
tempSkeleton.u_id =[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];//f_id
// NSString *strn = [NSString stringWithFormat:#"%#",tempSkeleton.mToID];
tempSkeleton.f_id=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
tempSkeleton.msg=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
//tempSkeleton.fromMe=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
// tempSkeleton.fromMe=((int)sqlite3_column_int(statement, 4)) ? YES : NO;
tempSkeleton.lft_rght=(int)sqlite3_column_int(statement, 4);
tempSkeleton.tim_dte=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 5)];
//if messageID Null
char *messageIDForEmptyCheck = (char *)sqlite3_column_text(statement, 6);
NSString *messageID1 = messageIDForEmptyCheck?[[NSString alloc]initWithUTF8String:messageIDForEmptyCheck]:#"";
tempSkeleton.messageID=messageID1;
//if chat status Null
char *chatStatus = (char *) sqlite3_column_text(statement,7);
NSString *chatStatus1 = chatStatus?[[NSString alloc]initWithUTF8String:chatStatus]:#"";
tempSkeleton.chatStatus=chatStatus1;
[array addObject:tempSkeleton];
// NSLog(#"IN LOOP=>%#",array);
}
}
return array;
}
I just alter table and added two columns messageID,chatstatus but these two values showing empty. What I am missing?
I'm having a problem where every time I click the button that calls on my MFMessageComposeViewController nothing happens. More specifically it freezes before it displays the controller and I am not able to do anything.
Here's my code:
- (IBAction)getQuote:(id)sender {
NSString * inputProduct =_productTextField.text;
NSString * inputYear = _yearTextField.text;
NSString * inputMake = _makeTextField.text;
NSString * inputEmail = email.text;
NSString * inputDescript = _descript.text;
emailConfirmation.text = email.text;
//email subject
NSString *emailTitle = #"Love Shack Electronics";
//email content
if ([conditionlabel isEqual: #"Fair"]) {
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Fair Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
[SuperLovedEmail setEditing:false];
If anyone can help or figure out what is wrong with my code it would be greatly appreciated.
Please check in device and latest Xcode version. it's work fine. it not work then put into dispatch method like below
dispatch_async(dispatch_get_main_queue(),
^{
if ([conditionlabel isEqual: #"Fair"])
{
NSString *emailBody = [NSString stringWithFormat:#"Product:%# Make:%# Year Manufactured:%# Description:%# Condition:Fair Email:%#",inputProduct,inputMake,inputYear,inputDescript, inputEmail];
NSArray *recipient = [NSArray arrayWithObject:#"LoveShackElectronics#gmail.com"];
MFMailComposeViewController *SuperLovedEmail = [[MFMailComposeViewController alloc]init];
[SuperLovedEmail setTitle:emailTitle];
[SuperLovedEmail setToRecipients:recipient];
[SuperLovedEmail setMessageBody:emailBody isHTML:NO];
[SuperLovedEmail setUserActivity:false];
[self presentViewController:SuperLovedEmail animated:YES completion:nil];
[SuperLovedEmail setEditing:false];
}
});
I'm having a difficulty with this one I have a method that returns a value of Array of NSDictionary once I pass the return value of an array first it works. I already get the object in my NSLog but when I try to access the objects of my Array of NSDictionary in another method I get the error and I think that I loses the objects of the array.
Here's the method that return an Array of NSDictionary:
-(NSMutableArray *)selectItemDataTbl {
NSMutableArray *l_array_data = [[NSMutableArray alloc] init];
NSString *query = #"SELECT pid, fname, gen_name, type, fu, fprice FROM tbl_selectItem_data";
sqlite3_stmt *l_statement;
if (sqlite3_open([l_SqliteDb UTF8String], &(_database)) == SQLITE_OK) {
if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &l_statement, nil) == SQLITE_OK) {
while(sqlite3_step(l_statement) == SQLITE_ROW){
NSMutableDictionary *l_dataDictionary = [[NSMutableDictionary alloc]init];
NSString *l_pid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(l_statement, 0)];
NSString *l_name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(l_statement, 1)];
NSString *l_genName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(l_statement, 2)];
NSString *l_Type = [NSString stringWithUTF8String:(char *)sqlite3_column_text(l_statement, 3)];
NSString *l_u = [NSString stringWithUTF8String:(char *)sqlite3_column_text(l_statement, 4)];
NSString *l_Price = [NSString stringWithUTF8String:(char *)sqlite3_column_text(l_statement, 5)];
[l_dataDictionary setObject:l_pid forKey:#"pid"];
[l_dataDictionary setObject:l_name forKey:#"name"];
[l_dataDictionary setObject:l_genName forKey:#"genName"];
[l_dataDictionary setObject:l_Type forKey:#"Type"];
[l_dataDictionary setObject:l_u forKey:#"u"];
[l_dataDictionary setObject:l_Price forKey:#"Price"];
[l_array_data addObject:l_dataDictionary];
}
NSLog(#"l_array_data count: %i", [l_array_data count]);
sqlite3_finalize(l_statement);
sqlite3_close(_database);
}
}
return l_array_data;
}
And here my method how I access it I'm calling it on my viewDidLoad:
- (void)selectItemData {
_l_alldataInSelectItem = [[NSMutableArray alloc] init];
_l_prodId = [[NSMutableArray alloc] init];
_l_prodName = [[NSMutableArray alloc] init];
_l_prodGenName = [[NSMutableArray alloc] init];
_l_prodCompType = [[NSMutableArray alloc] init];
_l_prodUom = [[NSMutableArray alloc] init];
_l_prodListPrice = [[NSMutableArray alloc] init];
_l_alldataInSelectItem = [dbc selectItemDataTbl];
_l_selectItemData_Dictionary = [[NSDictionary alloc] init];
for (_l_selectItemData_Dictionary in _l_alldataInSelectItem) {
NSString *Id = [_l_selectItemData_Dictionary valueForKey:#"pid"] ;
NSString *Name = [_l_selectItemData_Dictionary valueForKey:#"name"];
NSString *GenName = [_l_selectItemData_Dictionary valueForKey:#"genName"];
NSString *Type = [_l_selectItemData_Dictionary valueForKey:#"Type"];
NSString *U = [_l_selectItemData_Dictionary valueForKey:#"u"];
NSString *Price = [_l_selectItemData_Dictionary valueForKey:#"Price"];
[_l_prodId addObject:Id];
[_l_prodName addObject:Name];
[_l_prodGenName addObject:GenName];
[_l_prodCompType addObject:GenName];
[_l_prodUom addObject:U];
[_l_prodListPrice addObject:Price];
}
NSLog(#"adsfasdf %#", _l_prodId);
NSLog(#"adsfasdf %i", [_l_alldataInSelectItem count]);
}
But in this method I can't get the value of my array _l_alldataInSelectItem
- (void)textFieldshouldChange {
NSString *searchKey = self.txt_SearchField.text;
NSMutableArray *searchingData = [[NSMutableArray alloc] init];
if (![searchKey isEqualToString:#""]) {
NSLog(#"When TextField text is changed, this will be called");
NSLog(#"textFieldshouldChange _l_alldataInSelectItem: %i", [_l_alldataInSelectItem count]);
}
}
here's how i declare my l_alldataInSelectItem. I declared it on my header file
#property (strong, nonatomic) NSMutableArray *l_alldataInSelectItem, *l_prodId, *l_prodName, *l_prodGenName, *l_prodCompType, *l_prodUom, *l_prodListPrice;
Go systematically through the possibilities.
Possibility 1: There are gremlins somewhere trying to annoy you. We exclude that.
Possibility 2: You never created the data. Set a breakpoint on the return statement in selectItemDataTbl and check it.
Possibility 3: You never stored the array. Well, there is the fact that you store an empty mutable array into _l_alldataInSelectItem which is absolutely pointless, but set a breakpoint on the last statement in selectItemData and check it.
Possibility 4: You stored it and overwrote it. Search for all places where you store to _l_alldataInSelectItem or to a property named l_alldataInSelectItem, set breakpoints everywhere, and check.
Possibility 5 (the stupid one): _l_alldataInSelectItem is a weak instance variable or a weak property.
Possibility 6: You stored it, but looked for it in a different place. Is the self in textFieldshouldChange the same as the self in selectItemData? Set breakpoints and check.
Possibility 7: You are doing something asynchronously. The variable will be set, but much later than you think.
Most important: Put it very strongly in your mind that you did something wrong, and you don't have to solve any magical puzzles, all you need to do is find out what you did wrong.