I have created a quiz with 4 answers and one of them is right answer. Questions and answers I keep in plist.( where It have arrays of dictionaries).
Now I want to have more than one right answer to one question. Example: User can select A B C D or A C or B C D etc. and push button "next question".
Please tell me the right way to realize my mission!
Sorry for my ENG, I am Russian.
m.file
enter code here- (void)showNextQuestion
{
if ([self.highScore integerForKey:#"HighScore"]<numCorrect){
[self.highScore setInteger:numCorrect forKey:#"HighScore"];
[self.highScore synchronize];
}
currentQuestion++; //= arc4random()%10;
if (currentQuestion <= [self.questions count]){
self.labelScore.text = [NSString stringWithFormat:#"%d", numCorrect];
self.labelHighestScore.text = [NSString stringWithFormat:#"%d", [self.highScore integerForKey:#"HighScore"]];
NSDictionary* nextQuestion = [self.questions objectAtIndex: currentQuestion];//[self.questions objectForKey:[NSString stringWithFormat:#"%d", currentQuestion]];
NSString* correctAnswer = [nextQuestion objectForKey:#"CorrectAnswer"];
self.answer = correctAnswer;
self.labelA.text = [nextQuestion objectForKey:#"A"];
self.labelB.text = [nextQuestion objectForKey:#"B"];
self.labelC.text = [nextQuestion objectForKey:#"C"];
self.labelD.text = [nextQuestion objectForKey:#"D"];
self.labelQuestion.text = [nextQuestion objectForKey:#"QuestionTitle"];
NSLog(#"%d количество вопросов", countQuestion);
int questNumber = countQuestion+1;
NSString *questNumberString = [[NSString alloc] initWithFormat:#"%d", questNumber];
NSLog(#"%#", questNumberString);
questNum.text = questNumberString;
- (IBAction)buttonPressedA:(id)sender {
//AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: #"A" ]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:#"%d", numCorrect];
}
[self showNextQuestion];
}
- (IBAction)buttonPressedB:(id)sender {
// AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: #"B"]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:#"%d", numCorrect];
}
[self showNextQuestion];}
- (IBAction)buttonPressedC:(id)sender {
//AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: #"C"]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:#"%d", numCorrect];
}
[self showNextQuestion];}
- (IBAction)buttonPressedD:(id)sender {
//AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: #"D"]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:#"%d", numCorrect];
}
[self showNextQuestion];}
#end
Inside your plist, make the answer itself a dictionary. Use one key/value pair for the title and the other one to indicate if it is correct or not.
When the user selects an answer, you just have to check the corresponding boolean value (in this case "correct").
Related
In my application you can import data through a tab separated values file. I don't have any challenge until I parse "locations" that have multiple items attached to them. If you scroll to the very bottom of the second method you can see how I create a relationship between items and the locations that contain them inside Core Data. The problem occurs when I parse past column 31 in a location. It doesn't attach those items to the location. So my question is this; is there a limit to columns in the NSArray that is parsed by CHCSVParser? If not, what would cause this limiting to 31 columns?
I've posted the two methods that I encounter the bug with below.
+ (void) importDatabaseTSVURL:(NSURL*)url {
// First check if there is already a database. If so, stop import.
if ([XSELLocation locations].count > 0) return;
if ([XSELItem items].count > 0) return;
if ([XSELVendor vendors].count > 0) return;
NSError *error;
NSArray *array = [NSArray arrayWithContentsOfDelimitedURL:url options:CHCSVParserOptionsSanitizesFields delimiter:'\t' error:&error];
if ([[[array firstObject] firstObject] isEqualToString:#"XSELINVENTORYTSV"]) {
for (NSArray *row in array) {
[XSELSettings parseImportDataRow:row];
}
}
}
+ (void) parseImportDataRow:(NSArray*)array {
// Create logic to seperate data entered next
static NSString *operation = #"none";
if ([array.firstObject isEqualToString:#"ITEMLIST"]) {
operation = #"items";
return;
}
else if ([array.firstObject isEqualToString:#"LOCATIONLIST"]) {
operation = #"locations";
return;
}
else if ([array.firstObject isEqualToString:#"VENDORLIST"]) {
operation = #"vendors";
return;
}
else if ([array.firstObject isEqualToString:#"ENDLIST"]) { // Create database, relate objects, and clean up the data
operation = #"none";
return;
}
// Parse rows to the correct array.
if ([operation isEqualToString:#"vendors"]) {
NSLog(#"adding vendor");
XSELVendor *vendor = [XSELVendor addVendor];
vendor.vendorID = [NSNumber numberWithInteger:[[array objectAtIndex:0] integerValue]];
[XSELSettings nextVendorID];
vendor.name = [array objectAtIndex:1];
vendor.contactID = [array objectAtIndex:2];
}
else if ([operation isEqualToString:#"items"]) {
NSLog(#"adding item");
XSELItem *item = [XSELItem addItem];
item.itemID = [NSNumber numberWithDouble:[[array objectAtIndex:0] integerValue]];
[XSELSettings nextItemID];
item.name = [array objectAtIndex:1];
item.smallPackageName = [array objectAtIndex:2];
item.bigPackageName = [array objectAtIndex:3];
item.smallPerBig = [NSNumber numberWithDouble:[[array objectAtIndex:4] integerValue]];
item.buildTo = [NSNumber numberWithDouble:[[array objectAtIndex:5] integerValue]];
item.price = [NSNumber numberWithDouble:[[array objectAtIndex:6] integerValue]];
// Relate preferred vendor to item
for (XSELVendor *vendor in [XSELVendor vendors]) {
if ([vendor.vendorID.stringValue isEqualToString:[array objectAtIndex:7]]) {
item.preferredVendor = vendor;
break;
}
}
}
else if ([operation isEqualToString:#"locations"]) {
NSLog(#"adding location");
XSELLocation *location = [XSELLocation addLocation:[array objectAtIndex:1]];
location.locationID = [NSNumber numberWithInteger:[[array objectAtIndex:0] integerValue]];
[XSELSettings nextLocationID];
location.position = [NSNumber numberWithInteger:[[array objectAtIndex:2] integerValue]];
// Relate location with items
unsigned long itemsRelatedCount = array.count - 3;
NSLog(#"\n\nitemsRelated: %lu\n\n", itemsRelatedCount);
NSMutableOrderedSet *items = [NSMutableOrderedSet orderedSet];
for (int i = 0; i < itemsRelatedCount; i++) {
NSString *itemID = [array objectAtIndex:i];
for (XSELItem *item in [XSELItem items]) {
if ([item.itemID.stringValue isEqualToString:itemID]) {
[items addObject:item];
break;
}
}
}
location.items = items;
}
}
I am using NSMutableArray for adding objects.But its add only first 10 objects.
I have code for sharing
for (int j = 0; j<[feedData count]; j++)
{
[sharingItems addObject:[self whatsappdata:[feedData objectAtIndex:j]]];
}
This method return NSString type text.
Please provide me valid solution for this.
Thanks in Advance
-(NSString *)whatsappdata:(NSDictionary *)cellData1
{
NSString *brandName = [NSString stringWithFormat:#"%#", [cellData1 objectForKey:#"brand_name"]];
NSString *modelName = [NSString stringWithFormat:#"%#", [cellData1 objectForKey:#"brand_model_name"]];
NSString *version = [NSString stringWithFormat:#"%#", [cellData1 objectForKey:#"version_name"]];
if ([version isEqualToString: #"<null>"])
{
version = #"";
}
NSString *year = [NSString stringWithFormat:#"%#", [cellData1 objectForKey:#"model_year"]];
if (year == nil || [year isEqualToString:#"0"])
{
year = #"";
}
NSString *inventoryValue = [NSString stringWithFormat:#"%#",[cellData1 objectForKey:#"inventory_type"]];
NSInteger value = [inventoryValue intValue];
NSString *inventoryName;
NSString *msg;
if(value == 1)
{
inventoryName = [NSString stringWithFormat:#"%#", #"Stock"];
i++;
NSString *text2 = [NSString stringWithFormat:#"%d.%# %# %#- %# Single Owner\n",i, brandName, modelName, version, year];
msg = [NSString stringWithFormat:#"%#",text2];
msg= [msg stringByReplacingOccurrencesOfString:#"\n" withString:#"<br/>"];
}
else
{
inventoryName = [NSString stringWithFormat:#"%#", #"Required"];
msg = #"";
}
return msg;
//end data
}
Most probably "fetch limit" has set for 'NSFetchRequest' inside your code.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setFetchLimit:10];//such code you need to find and remove/change fetch limit
you need to allocate memory to array before adding elements
sharingItems = [[NSMutableArray alloc]init];
I am using SQLite and I want to save the name, address, and phone text fields for them to show up in the next view controller for when the "show details" button is clicked in 1st VC.
I placed "save" and "show details" button in 1st VC, as well as "previous" and "next" button in 2nd VC. Whenever I click on "show details" I am getting this error message:
index 0 beyond bounds for empty array.
However, I see that the array is not empty. I want to store the student details in the array.
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *homeDirectory = NSHomeDirectory();
NSString *documentsDirectoryPath = [homeDirectory stringByAppendingPathComponent:#"Documents"];
self.dbFilePathInDocuments = [documentsDirectoryPath stringByAppendingPathComponent:#"details.db"];
self.studentDetails = [[NSMutableArray alloc]init];
NSString *selectQuery = [NSString stringWithFormat:#"select name,address,phone from contacts"];
sqlite3_open([self.dbFilePathInDocuments UTF8String], &dataBase);
sqlite3_prepare_v2(dataBase, [selectQuery UTF8String], -1,&selectStatement, NULL);
while (sqlite3_step(selectStatement) == SQLITE_ROW)
{
NSMutableDictionary *studentDict = [[NSMutableDictionary alloc]init];
NSString *name = [NSString stringWithFormat:#"%s",sqlite3_column_text(selectStatement, 0)];
NSString *address = [NSString stringWithFormat:#"%s",sqlite3_column_text(selectStatement, 1)];
NSString *phone = [NSString stringWithFormat:#"%s",sqlite3_column_text(selectStatement, 2)];
[studentDict setObject:name forKey:#"name"];
[studentDict setObject:address forKey:#"address"];
[studentDict setObject:phone forKey:#"phone"];
[self.studentDetails addObject:studentDict];
NSLog(#"student is:%#",self.studentDetails);
}
sqlite3_finalize(selectStatement);
sqlite3_close(dataBase);
self.nameLabel.text = [[self.studentDetails objectAtIndex:0] valueForKey:#"name"];
self.addressLabel.text = [[self.studentDetails objectAtIndex:0] valueForKey:#"address"];
self.phoneLabel.text = [[self.studentDetails objectAtIndex:0] valueForKey:#"phone"];
currentStudentIndex = 0;
}
- (IBAction)clickPrevious:(id)sender {
if(currentStudentIndex <=0)
{
currentStudentIndex = 0;
}else
{
currentStudentIndex = currentStudentIndex - 1;
}
self.nameLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"name"];
self.addressLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"address"];
self.phoneLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"phone"];
}
- (IBAction)clickNext:(id)sender {
if(currentStudentIndex >= [self.studentDetails count] - 1)
{
currentStudentIndex = [self.studentDetails count] - 1;
}else
{
currentStudentIndex = currentStudentIndex + 1;
}
self.nameLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"name"];
self.addressLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"address"];
self.phoneLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"phone"];
}
The issue is that you always accessing the array self.studentDetails even if it's empty. This will cause an exception.
First limit setting of the labels to a single method and check the array access will succeed before attempting it:
- (void)updateLabels
{
if (currentStudentIndex >= [self.studentDetails count])
return;
self.nameLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"name"];
self.addressLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"address"];
self.phoneLabel.text = [[self.studentDetails objectAtIndex:currentStudentIndex] valueForKey:#"phone"];
}
and use that method in the 3 places you currently set the labels. For example:
- (IBAction)clickPrevious:(id)sender {
currentStudentIndex--;
[self updateLabels];
}
- (IBAction)clickNext:(id)sender {
currentStudentIndex++;
[self updateLabels];
}
In the viewDidLoad method use this code:
...
sqlite3_finalize(selectStatement);
sqlite3_close(dataBase);
currentStudentIndex = 0;
[self updateLabels];
After that you're gonna want to work on enabling/disabling buttons depending on whether there is a next or previous student to view to make using the app more intuitive.
I have a function to initialize an array of backpack objects, and a property of the backpack object is positive, negative, and neutral attributes, which are all NSStrings. The problem is that when I initialize the values of the attributes, the same value repeats twice (when I log the value of it)
The code:
#pragma mark - Creating Backpack Icons
-(NSArray *)createBackpackIcons:(NSArray *)groups usingItemGroups:(NSArray *)items
{
NSMutableArray *backpackItems = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < _groups.count; i++) {
Group *group = _groups[i];
NSString *defindex1 = [NSString stringWithFormat:#"%#", group.defindex];
for (NSInteger j = 0; j < _itemGroups.count; j++)
{
Item *item = _itemGroups[j];
NSString *defindex2 = [NSString stringWithFormat:#"%#", item.defindex];
if([defindex1 isEqualToString:defindex2])
{
//NSLog(#"%#", item.item_name);
backpackIcons *backpack = [[backpackIcons alloc] init];
backpack.pos_att = #"";
backpack.neg_att = #"";
backpack.neutral_att = #"";
//name of item
if([item.proper_name boolValue])
{
backpack.name = #"The ";
backpack.name = [backpack.name stringByAppendingString:item.item_name];
}
else
{
backpack.name = item.item_name;
}
backpack.original_id = group.original_id; //id of the item
backpack.defindex = item.defindex; //defindex number of the item
backpack.level = group.level; //level of the item
backpack.quality = group.quality; //quality of the item
backpack.image_url = item.image_url; //image of the item
backpack.item_description = item.item_description; //description of the item
backpack.image_url_large = item.image_url_large; //large image of the item
backpack.item_type = item.item_type_name; //type of item
//find origin of item
if(group.origin != NULL) {
backpack.origin = [item.originNames objectAtIndex:[group.origin integerValue]];
}
else {
backpack.origin = #"";
}
if([group.flag_cannot_craft boolValue])
{
//item isn't craftable
backpack.not_craftable = #"(Not Craftable)";
}
if([group.flag_cannot_trade boolValue])
{
//item isn't tradable
backpack.not_tradable = #"(Not Tradable)";
}
//custom name
if(group.custom_name != NULL) {
backpack.custom_name = group.custom_name;
}
//custom description
if(group.custom_desc != NULL) {
backpack.custom_desc = group.custom_desc;
}
//find positive and negative attributes of the item
if(group.attributes.count != 0) {
for(NSInteger num = 0; num < group.attributes.count; num++) {
NSString *att_def = [NSString stringWithFormat:#"%#",[[group.attributes objectAtIndex:num] valueForKey:#"defindex"]];
//NSLog(att_def);
for(NSInteger num2 = 0; num2 < item.attributes.count; num2++) {
NSString *att_def2 = [NSString stringWithFormat:#"%#", [[item.attributes objectAtIndex:num2] valueForKey:#"defindex"]];
//defindex of 214 is for counting kills on strange weapons
if(att_def2 != NULL) {
if ([att_def isEqualToString:att_def2]) {
//we have found the attribute!
if(![[[item.attributes objectAtIndex:num2] valueForKey:#"hidden"] boolValue]) {
//item isn't hidden from view
if(![[[item.attributes objectAtIndex:num2] valueForKey:#"stored_as_integer"] boolValue]) {
//we use the float value
if([[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"float_value"]] isEqualToString:#"1"] || [[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"float_value"]] isEqualToString:#"0"]) {
//the attribute is string only, it has no values
NSString *att_type = [[item.attributes objectAtIndex:num2] valueForKey:#"effect_type"];
NSString *attribute = [[item.attributes objectAtIndex:num2] valueForKey:#"description_string"];
if([att_type isEqualToString:#"positive"]) {
backpack.pos_att = [backpack.pos_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else if ([att_type isEqualToString:#"negative"]) {
backpack.neg_att = [backpack.neg_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else {
backpack.neutral_att = [backpack.neutral_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
}
}
else {
//the attribute uses values given my the float_value key
NSString *att_type = [[item.attributes objectAtIndex:num2] valueForKey:#"effect_type"];
double y = [[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"float_value"]] doubleValue];
NSInteger z;
if([[[item.attributes objectAtIndex:num2] valueForKey:#"description_string"] rangeOfString:#"%s1%"].location != NSNotFound) {
//for values with percentages
z = lroundf(y*100);
if(z >= 100) {
z = z - 100;
}
}
else {
//for values that are just integers
z = y;
}
NSString *a = [NSString stringWithFormat:#"%d", z];
NSString *attribute = [[[item.attributes objectAtIndex:num2] valueForKey:#"description_string"] stringByReplacingOccurrencesOfString:#"%s1" withString:a];
//NSLog(attribute);
if([att_type isEqualToString:#"positive"]) {
backpack.pos_att = [backpack.pos_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else if ([att_type isEqualToString:#"negative"]) {
backpack.neg_att = [backpack.neg_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else {
backpack.neutral_att = [backpack.neutral_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
}
}
}
else {
//we use the integer value
NSString *att_type = [[item.attributes objectAtIndex:num2] valueForKey:#"effect_type"];
NSInteger y = [[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"value"]] integerValue];
NSString *a = [NSString stringWithFormat:#"%d", y];
NSString *attribute = [[[item.attributes objectAtIndex:num2] valueForKey:#"description_string"] stringByReplacingOccurrencesOfString:#"%s1" withString:a];
if([att_type isEqualToString:#"positive"]) {
backpack.pos_att = [backpack.pos_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else if ([att_type isEqualToString:#"negative"]) {
backpack.neg_att = [backpack.neg_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else {
backpack.neutral_att = [backpack.neutral_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
}
}
}
}
}
}
}
}
[backpackItems addObject:backpack];
}
}
}
return backpackItems;
}
The actual code to set the values of the attributes:
if(![[[item.attributes objectAtIndex:num2] valueForKey:#"stored_as_integer"] boolValue]) {
//we use the float value
if([[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"float_value"]] isEqualToString:#"1"] || [[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"float_value"]] isEqualToString:#"0"]) {
//the attribute is string only, it has no values
NSString *att_type = [[item.attributes objectAtIndex:num2] valueForKey:#"effect_type"];
NSString *attribute = [[item.attributes objectAtIndex:num2] valueForKey:#"description_string"];
if([att_type isEqualToString:#"positive"]) {
backpack.pos_att = [backpack.pos_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else if ([att_type isEqualToString:#"negative"]) {
backpack.neg_att = [backpack.neg_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else {
backpack.neutral_att = [backpack.neutral_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
}
}
else {
//the attribute uses values given my the float_value key
NSString *att_type = [[item.attributes objectAtIndex:num2] valueForKey:#"effect_type"];
double y = [[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"float_value"]] doubleValue];
NSInteger z;
if([[[item.attributes objectAtIndex:num2] valueForKey:#"description_string"] rangeOfString:#"%s1%"].location != NSNotFound) {
//for values with percentages
z = lroundf(y*100);
if(z >= 100) {
z = z - 100;
}
}
else {
//for values that are just integers
z = y;
}
NSString *a = [NSString stringWithFormat:#"%d", z];
NSString *attribute = [[[item.attributes objectAtIndex:num2] valueForKey:#"description_string"] stringByReplacingOccurrencesOfString:#"%s1" withString:a];
//NSLog(attribute);
if([att_type isEqualToString:#"positive"]) {
backpack.pos_att = [backpack.pos_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else if ([att_type isEqualToString:#"negative"]) {
backpack.neg_att = [backpack.neg_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else {
backpack.neutral_att = [backpack.neutral_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
}
}
}
else {
//we use the integer value
NSString *att_type = [[item.attributes objectAtIndex:num2] valueForKey:#"effect_type"];
NSInteger y = [[NSString stringWithFormat:#"%#", [[group.attributes objectAtIndex:num] valueForKey:#"value"]] integerValue];
NSString *a = [NSString stringWithFormat:#"%d", y];
NSString *attribute = [[[item.attributes objectAtIndex:num2] valueForKey:#"description_string"] stringByReplacingOccurrencesOfString:#"%s1" withString:a];
if([att_type isEqualToString:#"positive"]) {
backpack.pos_att = [backpack.pos_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else if ([att_type isEqualToString:#"negative"]) {
backpack.neg_att = [backpack.neg_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
} else {
backpack.neutral_att = [backpack.neutral_att stringByAppendingString:[NSString stringWithFormat:#"%#\n", attribute]];
}
}
}
It seems that the problem was that my array groups.attributes containing the attributes for each item had each attribute twice, so I initialized it wrong. Thanks to everyone who helped.
I am trying to attach images to the email and send the email to my email add. The problem is that when i send out an email with 4 or 5 images attached, the app keeps processing for ever and eventually gets hanged and crashes and doesn't send the email. It is working fine with one image. I am using skpsmtp to send the mail. The same app is working fine in iOS5, but it hangs when I run it on iOS6, I am unable to send an mail as it hangs.
The code looks like this:
- (IBAction) SendEmail {
//supports multiple emails
BOOL bIsEmailValid = NO;
if ([txtTO.text rangeOfString:#","].location != NSNotFound) {
NSArray *arrEmails = [txtTO.text componentsSeparatedByString:#","];
DLog(#"Emails: %#", arrEmails);
if ([arrEmails count] > 0) {
for (int ctr = 0; ctr < [arrEmails count] ; ctr++) {
NSString *strEmail = [(NSString*)[arrEmails objectAtIndex:ctr] stringByReplacingOccurrencesOfString:#" " withString:#""];
if ([self IsValidEmail:strEmail]) {
bIsEmailValid = YES;
} else {
bIsEmailValid = NO;
break;
}
}
}
} else { // only 1 email entered
if ([self IsValidEmail:txtTO.text]) {
bIsEmailValid = YES;
} else {
bIsEmailValid = NO;
}
}
if (bIsEmailValid) {
[NSThread detachNewThreadSelector:#selector(ActivityViewLoading) toTarget:self withObject:nil];
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = FROM_EMAIL;
testMsg.toEmail = txtTO.text;
testMsg.relayHost = RELAY_HOST;
testMsg.requiresAuth = YES;
testMsg.login = EMAIL_LOGIN;
testMsg.pass = PASSWORD;
testMsg.subject = txtSubj.text;
testMsg.wantsSecure = YES;
testMsg.delegate = self;
testMsg.bccEmail = BCC_EMAIL;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *defStrName = [defaults stringForKey:#"keyEName"];
NSString *defStrContact = [defaults stringForKey:#"keyEContNo"];
NSString *defStrEmail = [defaults stringForKey:#"keyEEmailAdd"];
NSString *defStrDescr = [defaults stringForKey:#"keyEShortMessage"];
DLog(#"%# %# %# %#",defStrName, defStrContact, defStrEmail, defStrDescr);
NSMutableArray* parts = [[NSMutableArray alloc] init];
NSString *strhtml = [NSString stringWithFormat:#"<div>%#</div>",[txtDesc.text stringWithNewLinesAsBRs]];
NSString *defStrWebLinks = [defaults stringForKey:#"keyEwebLinks"];
NSArray *array = [defStrWebLinks componentsSeparatedByString:#"|"];
NSString *strTemp1 = [[array objectAtIndex:0] stringByReplacingOccurrencesOfString:#" " withString:#""];
NSString *strTemp2 = [[array objectAtIndex:1] stringByReplacingOccurrencesOfString:#" " withString:#""];
NSString *strFormat1 = [NSString stringWithFormat:#"<a href=\"\%#\"\>%#</a>",
strTemp1,strTemp1];
NSString *strFormat12 = [NSString stringWithFormat:#"<a href=\"\%#\"\>%#</a>",
strTemp2,strTemp2];
NSString *strComb = [NSString stringWithFormat:#"%# | %#",strFormat1,strFormat12];
strhtml = [strhtml stringByReplacingOccurrencesOfString:defStrWebLinks withString:strComb];
//DLog(#"%#",strhtml);
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/html",kSKPSMTPPartContentTypeKey,
strhtml,kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
[parts addObject:plainPart];
for (int nCtr = 0; nCtr < [arrPix count]; nCtr++) {
UIImageView *imageV = [arrPix objectAtIndex:nCtr];
if (imageV.image) {
NSData *imageData = UIImagePNGRepresentation(imageV.image);
NSString *strFileName = [NSString stringWithFormat:#"MyPicture-%d.jpeg",nCtr];
NSString *strFormat = [NSString stringWithFormat:#"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%#\"",strFileName];
NSString *strFormat2 = [NSString stringWithFormat:#"attachment;\r\n\tfilename=\"%#\"",strFileName];
NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey,
strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,#"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
[parts addObject:vcfPart];
}
}
testMsg.parts = parts;
[testMsg send];
}
Need some guidance. Thanks..
Change the image format from PNG to JPEG.
Hence change this line
NSData *imageData = UIImagePNGRepresentation(imageV.image);
to
NSData *imageData = UIImageJPEGRepresentation(imageV.image,0.9);
It will solve the problem...