ios App crash instantly after in-app purchase buying - ios

Basically, i am in really bad situation. Our team successfully develop and release new version of application with new feature, which users are able to buy (in-app purchases).
So, we have tested all new functionality with iTunes test user, and everything worked great, however, when we saw release version in appStore with real iTunes user, there is a huge problem. User just press button to buy in-app purchase, after he write password of his account and accept to buy this new information. Unfortunately, app crashes everytime after this action. And there is no actions after this.
Basically, for in-app purchases I use MKStoreKit.
So, I would like to present code of the following action:
- (IBAction)buyNewRequest:(id)sender
{
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:#"uiAction"
action:#"Обработчик нажатия кнопки"
label:#"Кнопка - отправить запрос. Экран - запроса кредитной истории бки"
value:[NSNumber numberWithInt:100]] build]];
if ([self checkValidaionTextFields])
{
[DejalBezelActivityView activityViewForView:self.view withLabel:#"Подождите..."].showNetworkActivityIndicator = YES;
self.sendButton.enabled = NO;
[[MKStoreManager sharedManager] buyFeature:#"ru.financemart.nbki"
onComplete:^(NSString* purchasedFeature,
NSData* purchasedReceipt,
NSArray* availableDownloads)
{
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:#"uiAction"
action:#"Уведомление подтверждения покупки БКИ"
label:#"Уведомление - покупка бки. Экран - отправки запроса кредитной истории БКИ"
value:[NSNumber numberWithInt:100]] build]];
NSString *stringReceipt = [NSString stringWithFormat:#"%#", purchasedReceipt];
stringReceipt = [stringReceipt stringByReplacingOccurrencesOfString:#" " withString:#""];
stringReceipt = [stringReceipt stringByReplacingOccurrencesOfString:#"<" withString:#""];
stringReceipt = [stringReceipt stringByReplacingOccurrencesOfString:#">" withString:#""];
NSString *base64Receipt = [self base64forData:purchasedReceipt];
NSString *hashDevelopKey = #"i5FnXIZ2aKjdn1Ru2VfLarbdCwbiJvfsnh9QTm9MB0I";
NSString *hashMD5 = #"";
hashMD5 = [hashMD5 stringByAppendingString:hashDevelopKey];
NSString *familyText = self.familyTextField.text;
NSString *nameText = self.nameTextField.text;
NSString *patronimicText = self.patronimicTextField.text;
NSString *passportID = self.passportID.text;
NSString *email = self.emailTextField.text;
NSString *dateOfBirth = dateOfBirthFormat;
NSString *passportDate = datePassportFormat;
NSString *regionForRequest = #"";
if ([[UnicomAPIConfigResponse lastResponse] cityByID:#(self.unicomProposalsModel.cityID).stringValue].ru_RU != nil) {
regionForRequest = [[UnicomAPIConfigResponse lastResponse] cityByID:#(self.unicomProposalsModel.cityID).stringValue].ru_RU;
}
hashMD5 = [hashMD5 stringByAppendingString:dateOfBirth];
hashMD5 = [hashMD5 stringByAppendingString:email];
hashMD5 = [hashMD5 stringByAppendingString:nameText];
hashMD5 = [hashMD5 stringByAppendingString:patronimicText];
hashMD5 = [hashMD5 stringByAppendingString:passportID];
hashMD5 = [hashMD5 stringByAppendingString:passportDate];
hashMD5 = [hashMD5 stringByAppendingString:base64Receipt];
hashMD5 = [hashMD5 stringByAppendingString:regionForRequest];
hashMD5 = [hashMD5 stringByAppendingString:familyText];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *stringToken = [[[[defaults valueForKey:#"deviceToken"] description]
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]]
stringByReplacingOccurrencesOfString:#" "
withString:#""];
hashMD5 = [hashMD5 stringByAppendingString:stringToken];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"dd.MM.yyyy"];
NSString *stringFromDate = [formatter stringFromDate:[NSDate date]];
hashMD5 = [hashMD5 stringByAppendingString:stringFromDate];
[DejalBezelActivityView activityViewForView:self.view withLabel:#"Отправляем..."].showNetworkActivityIndicator = YES;
[self.unicomService postNBKIRequestWithName:nameText WithFamily:familyText andPatronimic:patronimicText andDOB:dateOfBirth andPassport:passportID andPassportDate:passportDate andPartnerName:#"1" andEmail:email andToken:stringToken andReceipt:base64Receipt andHashKey:[self md5:hashMD5] andRegion:regionForRequest success:^(UnicomAPIRequestsNBKIResponse *response)
{
self.sendButton.enabled = YES;
} error:^(NSError *error) {
self.sendButton.enabled = YES;
[self performSelector:#selector(showError) withObject:nil afterDelay:2.0];
}]->addObserver( ^( TLSignal<NSDictionary *> *sender, NSDictionary *response )
{
[self performSelector:#selector(showSuccessPostRequest) withObject:nil afterDelay:0.0];
userModel = [CreditUserModel tlSharedInstance];
NSDictionary *dicta = [userModel.serverResponse valueForKey:#"result"];
NSString *dictb = [dicta valueForKey:#"id"];
NSMutableDictionary *paramNBKI = [[NSMutableDictionary alloc] init];
[paramNBKI setObject:dictb forKey:#"requestID"];
[paramNBKI setObject:self.familyTextField.text forKey:#"familyName"];
[paramNBKI setObject:self.nameTextField.text forKey:#"name"];
[paramNBKI setObject:self.patronimicTextField.text forKey:#"patronimic"];
[paramNBKI setObject:passportID forKey:#"passportID"];
[paramNBKI setObject:dateOfBirth forKey:#"dateOfBirth"];
[paramNBKI setObject:passportDate forKey:#"passportDate"];
[paramNBKI setObject:base64Receipt forKey:#"baseReceipt"];
[paramNBKI setObject:[self convertDate:[NSDate date]] forKey:#"requestDate"];
NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
if([[[defaults dictionaryRepresentation] allKeys] containsObject:#"nbkiHistory"])
{
NSMutableArray *nbkiHistory = [[NSMutableArray alloc] init];
nbkiHistory = [NSMutableArray arrayWithArray:[defaults valueForKey:#"nbkiHistory"]];
[nbkiHistory addObject:paramNBKI];
[defaults setObject:nbkiHistory forKey:#"nbkiHistory"];
NSLog(#"mykey found");
} else {
NSMutableArray *nbkiHistory = [[NSMutableArray alloc] init];
[nbkiHistory addObject:paramNBKI];
[defaults setObject:nbkiHistory forKey:#"nbkiHistory"];
}
self.sendButton.enabled = YES;
} );
}
onCancelled:^
{
self.sendButton.enabled = YES;
[DejalBezelActivityView removeViewAnimated:YES];
}];
}
}
So, after user accept in-app purchase you could see POST request to our server ([self.unicomService postNBKIRequestWithName:), but there are no requests in our server database log, so app crashes before this code. But, there are no code strings where are it is able to crash.

Related

EXC_BAD_ACCESS. Completion block

ANSWER
I heve a mistake when i call the fetchDailyForecast it should looks like
[self.fetchController fetchDailyForecast:self.currentLocation.coordinate completionBlock:^(DailyModel *newModel) {
_dailyCondition = newModel;
NSLog(#"newModel = %#", _dailyCondition);
}];
END
I try to use bloc's and wait but have a bad_access exaction. Firstly i call method from MangeDataController.m
[self.fetchController
fetchDailyForecast:self.currentLocation.coordinate
completionBlock:(void(^)(DailyModel *))_dailyCondition];
where the dailyCondition is instance of DailyModel.
Secondly here is fetchDailyForecast method realization in FetchController.m.
-(void)fetchDailyForecast:(CLLocationCoordinate2D)coordinate completionBlock:(void(^)(DailyModel *))completionBlock {
NSString *urlString = [NSString stringWithFormat:#"http://api.openweathermap.org/data/2.5/forecast/daily?lat=%f&lon=%f&units=imperial&cnt=7%#", coordinate.latitude, coordinate.longitude, _key];
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
[self fetchJSONfromURL:urlString completionBlock:^(NSDictionary *weatherData) {
completionBlock([[DailyModel alloc] dataFromDictionaryDaily:weatherData]); --- (here the bad access);
}];
}
and thirdly in fatchDailyForecast i call fetchJSONfromURL here is realization:
-(void)fetchJSONfromURL:(NSString *)urlString completionBlock:(void (^)(NSDictionary *))completionBlock {
NSLog(#"url = %#", urlString);
[_manager GET:urlString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responceObject) {
if (responceObject) {
completionBlock(responceObject);
} else {
NSLog(#"responce object error");
}
}
failure:^(NSURLSessionTask *operation, NSError *error){
NSLog(#"error %#", error);
}];
}
P.S. I think my mistake is that i try to pass day _dailyCondition but should pass something different. Thanks for any help!
**EDIT ------- DailyModel.m **
#import "DailyModel.h"
#implementation DailyModel
-(id)dataFromDictionaryDaily:(NSDictionary *)dic {
NSArray *arrayWithDictionarys = [dic objectForKey:#"list"];
NSDictionary *dictionaryWithWeekDays = [self indexKeyedDictionaryFromArray:arrayWithDictionarys];
// NSLog(#"dictionary with dayweeks = %#", dictionaryWithWeekDays);
_arrayWithTemp = [NSMutableArray new];
_arrayWithDate = [NSMutableArray new];
_arrayWithIcon = [NSMutableArray new];
for (int i = 0; i <= 6; i++) {
NSNumber* key = [NSNumber numberWithInt:i];
[self addValuesToArrayWithTemp:dictionaryWithWeekDays key:key index:i];
[self addValuesToArrayWithDate:dictionaryWithWeekDays key:key index:i];
[self addValueToArrayWithImage:dictionaryWithWeekDays key:key index:i];
}
return self;
}
- (NSDictionary *) indexKeyedDictionaryFromArray:(NSArray *)array
{
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
[array enumerateObjectsUsingBlock:
^(id obj, NSUInteger idx, BOOL *stop){
NSNumber *index = [NSNumber numberWithInteger:idx];
[mutableDictionary setObject:obj forKey:index];
}];
NSDictionary *result = [NSDictionary.alloc initWithDictionary:mutableDictionary];
return result;
}
-(void) addValuesToArrayWithTemp:(NSDictionary *)inputDic key:(NSNumber *)key index:(int)ind {
NSDictionary *currentDic = [inputDic objectForKey:key];
NSDictionary *temp = [currentDic objectForKey:#"temp"];
_tempLow = [temp objectForKey:#"min"];
_tempHigh = [temp objectForKey:#"max"];
_tempLow = [self convertToCelsius:_tempLow];
_tempHigh = [self convertToCelsius:_tempHigh];
NSString *tempString = [NSString stringWithFormat:#"%.02f / %.02f", _tempLow.floatValue , _tempHigh.floatValue];
[_arrayWithTemp insertObject:tempString atIndex:ind];
}
-(NSNumber *)convertToCelsius:(NSNumber *)far {
double f = (far.doubleValue - 32) / 1.8;
NSNumber *celsius = [NSNumber numberWithDouble:f];
return celsius;
}
-(void) addValuesToArrayWithDate:(NSDictionary *)inputDic key:(NSNumber *)key index:(int)ind {
NSDictionary *currenDic = [inputDic objectForKey:key];
NSNumber *tempNumber = [currenDic objectForKey:#"dt"];
double unixTimeStamp = tempNumber.doubleValue;
NSString* weekDay = [self convertToWeekDay:unixTimeStamp];
[_arrayWithDate insertObject:weekDay atIndex:ind];
}
-(NSString *)convertToWeekDay:(double) unixtime {
NSTimeInterval _interval = unixtime;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateFormat:#"EEEE"];
NSString *dateString = [formatter stringFromDate:date];
return dateString;
}
-(void) addValueToArrayWithImage:(NSDictionary *)inputDic key:(NSNumber *)key index:(int)ind {
NSDictionary *currenDic = [inputDic objectForKey:key];
NSArray *weatherArray = [currenDic objectForKey:#"weather"];
NSDictionary *weather = weatherArray[0];
_icon = [weather objectForKey:#"icon"];
_icon = [self currentImageString:_icon];
[_arrayWithIcon insertObject:_icon atIndex:ind];
}
-(NSString *)currentImageString:(NSString *)ico {
NSDictionary *dic = #{
#"01d" : #"weather-clear",
#"02d" : #"weather-few",
#"03d" : #"weather-few",
#"04d" : #"weather-broken",
#"09d" : #"weather-shower",
#"10d" : #"weather-rain",
#"11d" : #"weather-tstorm",
#"13d" : #"weather-snow",
#"50d" : #"weather-mist",
#"01n" : #"weather-moon",
#"02n" : #"weather-few-night",
#"03n" : #"weather-few-night",
#"04n" : #"weather-broken",
#"09n" : #"weather-shower",
#"10n" : #"weather-rain-night",
#"11n" : #"weather-tstorm",
#"13n" : #"weather-snow",
#"50n" : #"weather-mist",
};
ico = [dic objectForKey:ico];
return ico;
}
#end
EDIT 2
I add the condition into (void)fetchDailyForecast:(CLLocationCoordinate2D)coordinate completionBlock:(void(^)(DailyModel *))completionBlock and now app don't crash but it's still not work and nslog say #"nothing"
[self fetchJSONfromURL:urlString completionBlock:^(NSDictionary
*weatherData) { if (completionBlock) { completionBlock(model = [[DailyModel alloc] dataFromDictionaryDaily:weatherData]); } else {
NSLog(#"nothing"); } }];

can't get images for any contact from contact book

Below is my code but with this code i can't get image for any contact.
Please help me for this.
- (void)loadAddressBook
{
arrContacts = [[NSMutableArray alloc]init];
APAddressBook *addressBook = [[APAddressBook alloc] init];
[addressBook loadContacts:^(NSArray <APContact *> *contacts, NSError *error)
{
if (!error)
{
for (APContact *strcontact in contacts)
{
NSMutableDictionary *addressDict=[[NSMutableDictionary alloc]init];
[addressDict setValue:strcontact.name.compositeName forKey:COMPOSITENAME];
if (strcontact.thumbnail != nil)
{
NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(strcontact.thumbnail)];
// From data to string
NSString *strImage = [[NSString alloc] initWithData:imgData encoding:NSUTF8StringEncoding];
[addressDict setObject:strImage forKey:IMAGE];
}else {
[addressDict setObject:NOIMAGE forKey:IMAGE];
}
for (APPhone *phones in strcontact.phones) {
// NSLog(#"Number %#",phones.number);
[addressDict setValue:phones.number forKey:PHONE];
}
for (APEmail *emails in strcontact.emails) {
// NSLog(#"Emails %#",emails.address);
[addressDict setValue:emails.address forKey:EMAIL];
}
for (APAddress *address in strcontact.addresses) {
// NSLog(#"Number %#",phones.number);
[addressDict setValue:address forKey:ADDRESS];
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = #"dd.MM.yyyy";
NSString *strDate = [formatter stringFromDate:[NSDate date]];
[addressDict setValue:strDate forKey:IMPORTDATE];
[arrContacts addObject:addressDict];
}
[tblmportContacts reloadData];
}
else
{
// show error
}
}];
}
I am getting all details but can not get images from APAddressBook.
Please provide solution for this.
Try code below.
addressBook.fieldsMask = APContactFieldAll;

GCD slow updating UI

Im using GCD to download a plist file from the internet then enter the data into an array then load it into a tableView.
The data is being downloaded and converted alright but the table view is taking ages to update. I have the app Logging something when it calls [self.tableView reloadData] but the table view updates about 10 seconds later.
I don't think this is about the table view because I tried changing the title of the Navigation Bar inside the GCD and there was also a delay. So it might be a delay updating the user interface?
This is my GCD code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Thanks for you help
EDIT:
This is my code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UERootArray = [[NSArray alloc] initWithContentsOfURL:[NSURL URLWithString:#"url to file"]];
NSLog(#"Array: %#", UERootArray);
//NSLog(#"count %#",count);
NSString *currentName;
NSString *currentLoaction;
NSString *currentDate;
int currentEventInt = 0;
NSArray *currentEventArr = [UERootArray objectAtIndex:0];
while (currentEventArr.count > currentEventInt)
{
currentName = [currentEventArr objectAtIndex:0];
currentLoaction = [currentEventArr objectAtIndex:1];
currentDate = #"7pm 17/11"; //[currentEventArr objectAtIndex:2];
NSLog (#"Title: %#", currentName);
NSLog (#"News: %#", currentLoaction);
NSLog (#"Date: %#", currentDate);
UEEvent *currentTask = [[UEEvent alloc] initWithName:currentName location:currentLoaction date:currentDate];
[self.upcommingEvents addObject:currentTask];
currentEventInt = currentEventInt + 1;
}
UEDownloaded = YES;
[self.tableView reloadData];
Edit 2:
- (void)downloadUEData
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UERootArray = [[NSArray alloc] initWithContentsOfURL:[NSURL URLWithString:#"url to file"]];
[self processUEData];
});
}
- (void)processUEData
{
NSLog(#"Array: %#", UERootArray);
//NSLog(#"count %#",count);
NSString *currentName;
NSString *currentLoaction;
NSString *currentDate;
int currentEventInt = 0;
NSArray *currentEventArr = [UERootArray objectAtIndex:0];
while (currentEventArr.count > currentEventInt)
{
currentName = [currentEventArr objectAtIndex:0];
currentLoaction = [currentEventArr objectAtIndex:1];
currentDate = #"7pm 17/11"; //[currentEventArr objectAtIndex:2];
NSLog (#"Title: %#", currentName);
NSLog (#"News: %#", currentLoaction);
NSLog (#"Date: %#", currentDate);
UEEvent *currentTask = [[UEEvent alloc] initWithName:currentName location:currentLoaction date:currentDate];
[self.upcommingEvents addObject:currentTask];
currentEventInt = currentEventInt + 1;
}
UEDownloaded = YES;
[self.tableView reloadData];
}
i think following code will solve your problem ...
- (void)downloadUEData
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UERootArray = [[NSArray alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://www.nytrex.webs.com/Linx/upcommingEvents.plist"]];
[self processUEData];
});
}
- (void)processUEData
{
NSLog(#"Array: %#", UERootArray);
//NSLog(#"count %#",count);
NSString *currentName;
NSString *currentLoaction;
NSString *currentDate;
int currentEventInt = 0;
NSArray *currentEventArr = [UERootArray objectAtIndex:0];
while (currentEventArr.count > currentEventInt)
{
currentName = [currentEventArr objectAtIndex:0];
currentLoaction = [currentEventArr objectAtIndex:1];
currentDate = #"7pm 17/11"; //[currentEventArr objectAtIndex:2];
NSLog (#"Title: %#", currentName);
NSLog (#"News: %#", currentLoaction);
NSLog (#"Date: %#", currentDate);
UEEvent *currentTask = [[UEEvent alloc] initWithName:currentName location:currentLoaction date:currentDate];
[self.upcommingEvents addObject:currentTask];
currentEventInt = currentEventInt + 1;
}
UEDownloaded = YES;
dispatch_async(dispatch_get_main_queue(), ^{ // update your UI in main thread
[self.tableView reloadData];
});
}

IOS Potential Leak an Object Message

I am developing an IOS application. I am fully understand the logic of the memory management. I did analyze with Xcode instruments then I saw "Potential leak an object" message. What is wrong with the code below. Can you help me please ?
-(CountriesDTO*)getNationalityCountry{
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSString *userNationality = (([def stringForKey:#"passCitizenshipCountry"]!=nil && [def stringForKey:#"passCitizenshipCountry"]!=NULL)?[def stringForKey:#"passCitizenshipCountry"]:#"");
CountriesDTO *ct = [self getCountryForCode:userNationality];
return ct; **//Potential leak of an object**
}
-(CountriesDTO*)getUserPhoneCodeCountry{
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSString *userPhoneCode = (([def stringForKey:#"countryPhoneFlagCode"]!=nil && [def stringForKey:#"countryPhoneFlagCode"]!=NULL)?[def stringForKey:#"countryPhoneFlagCode"]:#"");
CountriesDTO *ct = [self getCountryForCode:userPhoneCode];
return ct; **//Potential leak of an object**
}
-(CountriesDTO*)getCountryForCode:(NSString*)candidateCode{
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSString *userSiteCountry = (([def stringForKey:#"userSiteUrlCountry"]!=nil && [def stringForKey:#"userSiteUrlCountry"]!=NULL)?[def stringForKey:#"userSiteUrlCountry"]:#"");
NSString *defCode = #"";
if (![candidateCode isEqualToString:#""]) {
//Kullanıcının profilindeki nationality veya phone code dolu ise bu kullanılır.
defCode = candidateCode;
}else{
defCode=#"TR";
}
DatabaseController *db = [[[DatabaseController alloc] init] autorelease];
CountriesDTO *ct = [db getCountry:defCode];
if (ct==nil) {
ct = [[CountriesDTO alloc] init];
ct.countryCode_=#"";
ct.countryId_=#"";
ct.countryName_=#"";
ct.countryPhoneCode_=#"";
}
return ct; **//Potential leak of an object**
}
-(CountriesDTO*)getCountry:(NSString*)countryCode{
CountriesDTO *model=[[[CountriesDTO alloc] init] autorelease];
if (![db open]) {
[db release];
}else{
FMResultSet *s = [db executeQuery:[NSString stringWithFormat:#"SELECT * FROM country Where code ='%#'",countryCode]];
while ([s next]) {
//retrieve values for each record
[model setCountryId_:[s stringForColumn:#"id"]];
[model setCountryCode_:[s stringForColumn:#"code"]];
[model setCountryPhoneCode_:[s stringForColumn:#"phoneCode"]];
[model setCountryName_:[s stringForColumn:#"name"]];
}
[db close];
}
return model;
}
You are allocating ct and never releasing it:
ct = [[CountriesDTO alloc] init];
Use autorelease there:
ct = [[[CountriesDTO alloc] init] autorelease];

Sending more than 2 images via email with skpsmtpmessage in ios6

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...

Resources