Tips

#define DOCSFOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

#pragma mark Email function

-(IBAction)emailContact{
NSLog(@”email”);
[self emailApplicationDetail];
}

-(void) emailApplicationDetail
{
NSLog(@”ViewContactController ================> emailContactController”);
Class mailClass = (NSClassFromString(@”MFMailComposeViewController”));
if (mailClass != nil)
{
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}

}

-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
//picker.mailComposeDelegate = self;
[picker setSubject:@""];
NSString *emailBody = @”";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSLog(@”ViewContactController ================> mailComposserController”);
NSString * emailStatus;
switch (result)
{
case MFMailComposeResultCancelled:
emailStatus = @”Email canceled”;
break;
case MFMailComposeResultSaved:
emailStatus = @”Email saved”;
break;
case MFMailComposeResultSent:
emailStatus = @”Emailsent”;
break;
case MFMailComposeResultFailed:
emailStatus = @”Email failed”;
break;
default:
emailStatus = @”Email not sent”;
break;
}
[self dismissModalViewControllerAnimated:YES];
/*UIAlertView * alert1 = [[UIAlertView alloc] initWithTitle:@”Step3″ message:emailStatus
delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil];
[alert1 show];
[alert1 release];*/

}

-(void)launchMailAppOnDevice
{
NSLog(@”ViewContactController ================> launchMailAppOnDevice”);
NSString *recipients = @”mailto:?&ampsubject=”;
NSString *body = @”&body=”;
NSString *email1 = [NSString stringWithFormat:@"%@%@", recipients, body];
email1 = [email1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email1]];
}

-(IBAction)CallContact{
NSLog(@”contact id %@”,primary.text);
NSLog(@”primary for call : – %@”,primary.text);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",primary.text]]];
}

-(IBAction)smsContact{
NSLog(@”secondary for call : – %@”,secondary.text);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",secondary.text]]];
}

-(UIImage *)generateThumbnail:(UIImage *)image {
// Create a thumbnail version of the image for the event object.
CGSize size = image.size;
CGSize croppedSize;
CGFloat ratio = 64.0;
CGFloat offsetX = 0.0;
CGFloat offsetY = 0.0;

// check the size of the image, we want to make it
// a square with sides the size of the smallest dimension
if (size.width > size.height) {
offsetX = (size.height – size.width) / 2;
croppedSize = CGSizeMake(size.height, size.height);
} else {
offsetY = (size.width – size.height) / 2;
croppedSize = CGSizeMake(size.width, size.width);
}

// Crop the image before resize
CGRect clippedRect = CGRectMake(offsetX * -1, offsetY * -1, croppedSize.width, croppedSize.height);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
// Done cropping

// Resize the image
CGRect rect = CGRectMake(0.0, 0.0, ratio, ratio);

UIGraphicsBeginImageContext(rect.size);
[[UIImage imageWithCGImage:imageRef] drawInRect:rect];
UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Done Resizing

return thumbnail;
}

-(IBAction)setSegment{
NSLog(@”in segment”);

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@”in touchesBegan”);
for (UITouch *touch in touches) {
if(CGRectContainsRect(touch.view.frame, self.view.frame)){
[self dispatchTouchAtPoint:[touch locationInView:self.view] forEvent:nil];

}
}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@”PhotoDragController ================> touchesEnded”);
NSLog(@”in touchesEnded”);
if([selected isEqualToString:@"yes"]){
for (UITouch *touch in touches) {
NSString * selectedImage=[fileArray objectAtIndex:seq];
for(int i=0;i<3;i++){
if (CGRectContainsPoint([folderView[i] frame], [touch locationInView:self.view])){
NSLog(@"folder view %@",[folderArray objectAtIndex:i]);
NSLog(@"folder view %d",fseqArray[i]);
NSLog(@"selected image is %@",[fileArray objectAtIndex:seq]);
dir =[NSString stringWithFormat:@"%@/%@",DOCSFOLDER,[folderArray objectAtIndex:fseqArray[i]]];
NSLog(@"dir===%@",dir);
int i=0;
NSString * uniquePath = [dir stringByAppendingPathComponent:[fileArray objectAtIndex:seq]];
while ([[NSFileManager defaultManager] fileExistsAtPath:uniquePath]) {
NSString * fileName = [NSString stringWithFormat:@"%@-%d.%@",@"Image",++i,@"png"];
uniquePath = [NSString stringWithFormat:@"%@/%@", dir,fileName];
}

if (CGRectContainsPoint([imgDelete frame], [touch locationInView:self.view])){
NSLog(@"delete from dir %@",selectedDir);
NSString * deleteFrom = [NSString stringWithFormat:@"%@/%@/%@",DOCSFOLDER,selectedDir,[fileArray objectAtIndex:seq]];
NSLog(@"delete From %@",deleteFrom);
[[NSFileManager defaultManager] removeItemAtPath:deleteFrom error:nil];
dir=[NSString stringWithFormat:@"%@/%@",DOCSFOLDER,selectedDir];
[imgPathArray removeAllObjects];
for(int j=0;j dispatchTouchAtPoint”);
NSLog(@”in dispatchTouchAtPoint”);
for(int i=0;i<=maxseq;i++){
if (CGRectContainsPoint([imageView[i] frame], touchPoint)){
NSLog(@"imageview %d",i);
imageMove.image=imageView[i].image;
seq=seqArray[i];
NSString * Name = [imgPathArray objectAtIndex:seq];
NSLog(@"selected image is %@",Name);
NSLog(@"selected image is %@",[fileArray objectAtIndex:seq]);
selected=@"yes";
break;
}
}
for(int i=0;i<3;i++){
if (CGRectContainsPoint([folderView[i] frame], touchPoint)){
no=0;
[imgPathArray removeAllObjects];
for(int j=0;j < maxseq+1;j++)
[imageView[j] removeFromSuperview];
NSLog(@"folder view %@",[folderArray objectAtIndex:i]);
NSLog(@"folder view %d",fseqArray[i]);
fseqNo=fseqArray[i];
dir =[NSString stringWithFormat:@"%@/%@",DOCSFOLDER,[folderArray objectAtIndex:fseqArray[i]]];
selectedDir = [folderArray objectAtIndex:fseqArray[i]];
[self loadImageFiles];
[self loadImages];
if([imgPathArray count]<12){
btnNext.enabled=FALSE;
btnPrevious.enabled=FALSE;
}
else{
btnNext.enabled=TRUE;
}
break;
}

}
for(int i=0;i [imgPathArray count]){
btnNext.enabled=FALSE;
}
[self loadImages];
}

}
-(IBAction)previous{
no=no-12;
if(no==0){
btnPrevious.enabled=FALSE;
if([imgPathArray count]>12)
btnNext.enabled=TRUE;
}

[self loadImages];
}

-(void) dispatchTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event {
NSLog(@”PhotoDragController ================> dispatchTouchAtPoint”);
NSLog(@”in dispatchTouchAtPoint”);
for(int i=0;i<=maxseq;i++){
if (CGRectContainsPoint([imageView[i] frame], touchPoint)){
NSLog(@"imageview %d",i);
imageMove.image=imageView[i].image;
seq=seqArray[i];
NSString * Name = [imgPathArray objectAtIndex:seq];
NSLog(@"selected image is %@",Name);
NSLog(@"selected image is %@",[fileArray objectAtIndex:seq]);
selected=@"yes";
break;
}
}
for(int i=0;i<3;i++){
if (CGRectContainsPoint([folderView[i] frame], touchPoint)){
no=0;
[imgPathArray removeAllObjects];
for(int j=0;j < maxseq+1;j++)
[imageView[j] removeFromSuperview];
NSLog(@"folder view %@",[folderArray objectAtIndex:i]);
NSLog(@"folder view %d",fseqArray[i]);
fseqNo=fseqArray[i];
dir =[NSString stringWithFormat:@"%@/%@",DOCSFOLDER,[folderArray objectAtIndex:fseqArray[i]]];
selectedDir = [folderArray objectAtIndex:fseqArray[i]];
[self loadImageFiles];
[self loadImages];
if([imgPathArray count]<12){
btnNext.enabled=FALSE;
btnPrevious.enabled=FALSE;
}
else{
btnNext.enabled=TRUE;
}
break;
}

}
for(int i=0;i<3;i++){
if(i==[folderArray count])
break;
if(fseqNo==fseqArray[i]){
[folderView[i] setImage:[UIImage imageNamed:@"folder_icn_o.png"]];

}
else{
[folderView[i] setImage:[UIImage imageNamed:@"folder_icn.png"]];
}
}
}

for kisdds connection

iphone code snnipet
//in h file

#import
#import

AVAudioPlayer * player;
BOOL isRunnig;
@property BOOL isRunnig;
@property (nonatomic, retain)AVAudioPlayer * player;

@synthesize isRunnig , player;
//in view did load

isRunnig=YES;
player = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@”A” ofType:@”wav”]]
error:nil];
[player prepareToPlay];
[NSThread detachNewThreadSelector:@selector(playSong) toTarget:self withObject:nil];

- (void)playSong {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

while(isRunnig){

[player play];

}

[pool release];
}

//to stop song

isRunnig=NO;
[player stop];
[player release];

Comments are closed.

Follow

Get every new post delivered to your Inbox.