Loading

Wednesday, September 7, 2011

Upload Song from iPod Library to Webserver using ASIHTTPRequest

1. in Your .h file

     #import
    and use include MPMediaPickerControllerDelegate


2. in .m file where your brows button
     MPMediaPickerController *picker =[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];

picker.delegate = self;
        picker.allowsPickingMultipleItems = YES;
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
      [self presentModalViewController:picker animated:YES];
        [picker release];

3.  #pragma mark -

#pragma mark Media Picker Delegate Methods

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) theCollection {   

NSArray *ArrItems=theCollection.items;
MPMediaItem *curItem = [ArrItems objectAtIndex:0]; 
NSString *SongName=[curItem valueForProperty:MPMediaItemPropertyTitle];

NSURL *assetURL = [curItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
                                           initWithAsset:songAsset
                                           presetName:AVAssetExportPresetPassthrough];
NSArray *tracks = [songAsset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack *track = [tracks objectAtIndex:0];
id desc = [track.formatDescriptions objectAtIndex:0];
const AudioStreamBasicDescription *audioDesc = CMAudioFormatDescriptionGetStreamBasicDescription((CMAudioFormatDescriptionRef)desc);
    FourCharCode formatID = audioDesc->mFormatID;
NSString *fileType = nil;
NSString *ex = nil;
switch (formatID) {
            
        case kAudioFormatLinearPCM:
        {
            UInt32 flags = audioDesc->mFormatFlags;
            if (flags & kAudioFormatFlagIsBigEndian) {
                fileType = @"public.aiff-audio";
                ex = @"aif";
            } else {
                fileType = @"com.microsoft.waveform-audio";
                ex = @"wav";
            }
        }
            break;
            
        case kAudioFormatMPEGLayer3:
            fileType = @"com.apple.quicktime-movie";
            ex = @"mp3";
break;
            
        case kAudioFormatMPEG4AAC:
            fileType = @"com.apple.m4a-audio";
            ex = @"m4a";
            break;
            
        case kAudioFormatAppleLossless:
            fileType = @"com.apple.m4a-audio";
            ex = @"m4a";
            break;
            
        default:
            break;
    }
exportSession.outputFileType = fileType;
NSString *exportFile = [[self myDocumentsDirectory] stringByAppendingPathComponent:           
[NSString stringWithFormat:@"%@.%@",SongName,ex]];
NSURL *exportURL = [[NSURL fileURLWithPath:exportFile] retain];
exportSession.outputURL = exportURL; 
// do the export
// (completion handler block omitted) 
[exportSession exportAsynchronouslyWithCompletionHandler:
^{
NSData *Songdata = [NSData dataWithContentsOfFile: [[self myDocumentsDirectory
stringByAppendingPathComponent: [NSString stringWithFormat:@"%@.%@",SongName,ex]]];
 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:uploadSong]];
[request setDelegate:self];
NSString *UserID = [[NSUserDefaults standardUserDefaults]objectForKey:@"USERID"];
 
[request setPostValue:@"23" forKey:@"user_id"];
[request setPostValue:@"1" forKey:@"category_id"];
[request addData:Songdata withFileName:SongName andContentType:ex forKey:@"upload_song"];
[request startAsynchronous];
 
}];


[self dismissModalViewControllerAnimated: YES];
}
-(NSString *)myDocumentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}

4.

#pragma mark 
#pragma mark ASIHTTPRequestDelegate Methods
- (void)requestFinished:(ASIHTTPRequest *)request 
{
NSString *receivedString = [request responseString];
NSLog(@"%@",receivedString);
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSString *receivedString = [request responseString];
NSLog(@"%@",receivedString);
}
- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
{
NSString* str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",str);
} 






Monday, August 22, 2011

Open Doc Files from Another Application

1. in AppDelegate
if (launchOptions && [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey])
{

printf("Launch options:\n");
CFShow(launchOptions);
NSString *filePath = [NSString stringWithFormat:@"%@", (NSURL*)[launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSMutableArray *ArrTmp;
if ([[prefs objectForKey:@"DocArray"] count])
{
ArrTmp=[[prefs objectForKey:@"DocArray"] mutableCopy];
}
else
{
ArrTmp=[[NSMutableArray alloc] init];
}
[ArrTmp addObject:filePath];
[prefs setObject:ArrTmp forKey:@"DocArray"];

}


2. Add These Value in infoPList


CFBundleDocumentTypes


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
PDF
CFBundleTypeRole
Editor
LSItemContentTypes

com.adobe.pdf

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
BMP
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.bmp

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
W8BN
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.word.doc

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
XLS8
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.excel.xls

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary


CFBundleTypeIconFile
Icon.png
CFBundleTypeName
SLD8
CFBundleTypeRole
Editor
LSItemContentTypes

com.microsoft.powerpoint.​ppt

LSTypeIsPackage

NSDocumentClass
Document
NSPersistentStoreTypeKey
Binary




Now it handle PDF,Doc,Xls,Ppt files and you have all open files in Userdefault named "DocArray"

Refernce :- http://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

Monday, July 25, 2011

Add a image layer over camera

ImagePicker = [[UIImagePickerController alloc] init];
ImagePicker.delegate = self;
#if TARGET_IPHONE_SIMULATOR
ImagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#elif TARGET_OS_IPHONE
ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *ImgOutline=[[UIImageView alloc] initWithFrame:CGRectMake(20, 28, 124, 404)];
ImgOutline.image=[UIImage imageNamed:@"outline.png"];
[ImagePicker.view addSubview:ImgOutline];
#endif

ImagePicker.navigationController.navigationBar.barStyle = UIBarStyleBlack;
ImagePicker.editing = YES;
[self presentModalViewController:ImagePicker animated:YES];
[ImagePicker release];

Thursday, June 2, 2011

water effect with basic animation iphone sdk

I have found a good animation effect from google (Hidden Property)

CATransition *transition = [CATransition animation];
transition.type = @"rippleEffect";
transition.duration = 1.0f;
transition.timingFunction = UIViewAnimationCurveEaseInOut;
[self.view.layer addAnimation:transition forKey:@"transitionViewAnimation"];

we can use suckEffect and spewEffect similarly

Thursday, May 5, 2011

A Static Array That can be used anywhere in Application

1. Create a new plist file


named it suppose DictArr

2.

now add values in in this plist as


3.

Now where you wants to access these value
use This code
NSString *path = [[NSBundle mainBundle] pathForResource:@"DictArr" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
Arralbum=[dict objectForKey:@"ArrAlbum"];

Wednesday, February 2, 2011

Create Third Party Ads Through WebView

First we create a view controller named MyAds

in MyAds.h


@interface MyAds : UIViewController
{
IBOutlet UIWebView *Web_Ad;
NSString *formatStr;

UINavigationController *ng;
id parentController;

IBOutlet UIView *viewAdDesc;
IBOutlet UIWebView *Web_Ad_Detail;

}
-(void)initWithStr:(NSString*)str;
-(IBAction)btnCancel_Clicked:(id)sender;
@property(nonatomic, retain) id ParentController;
@property (nonatomic, retain) IBOutlet UINavigationController *ng;
@end


in MyAds.m


#import "MyAds.h"

@implementation MyAds
@synthesize ParentController = parentController;
@synthesize ng;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[Web_Ad setBackgroundColor:[UIColor clearColor]];
[Web_Ad setOpaque:NO];
[Web_Ad loadHTMLString:formatStr baseURL:[NSURL URLWithString:@"http://www.ashiphone.blogspot.com/"]];
}
-(void)initWithStr:(NSString*)str
{
formatStr=str;
[formatStr retain];
}

#pragma mark WebviewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"Page Start Loading");
if(webView==Web_Ad_Detail)
return YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURL *urlReq=[request URL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if([urlReq isEqual:[NSURL URLWithString:@"http://www.ashiphone.blogspot.com/"]])
NSLog(@"YES");
else if(urlReq)
{
[Web_Ad stopLoading];
[Web_Ad loadHTMLString:formatStr baseURL:[NSURL URLWithString:@"http://www.ashiphone.blogspot.com/"]];
[parentController addSubview:viewAdDesc];
ng.navigationBarHidden = YES;
[Web_Ad_Detail loadRequest:request];
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{


}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{

}

-(IBAction)btnCancel_Clicked:(id)sender
{
[viewAdDesc removeFromSuperview];
ng.navigationBarHidden = NO;
}




- (void)viewDidUnload {
[super viewDidUnload];
}


- (void)dealloc {
[super dealloc];
}


@end




Now We Have To Include This View As SubView Where We Wants the Ads

MyAds* childObject = [[MyAds alloc]initWithNibName:@"MyAds" bundle:[NSBundle mainBundle]];
childObject.ParentController=self.view;
childObject.ng = self.navigationController;
[childObject initWithStr:formatStr];
// formatStr is NSString with HTML code

Tuesday, February 1, 2011

Crop Image From ImageView by touch

#pragma mark touches Working
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
StartPoint = [touch locationInView:touch.view];

}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
EndPoint = [touch locationInView:touch.view];
}

-(IBAction)BtnDoneTouchInside
{

CGFloat width=EndPoint.x-StartPoint.x;
CGFloat hieght=EndPoint.y-StartPoint.y;
CGRect myImageRect = CGRectMake(StartPoint.x, StartPoint.y, width, hieght);
UIImageView *Img_Screen= [[UIImageView alloc] initWithFrame:myImageRect];

CGImageRef imageRef = CGImageCreateWithImageInRect([ImgMain.image CGImage], myImageRect);
// or use the UIImage wherever you like
[Img_Screen setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
[CropImageView addSubview:Img_Screen];

}

Monday, January 24, 2011

Build Multiple Projects From One Code

1--> Suppose your main project is MainProject.xcodeproj, The very first step is open project in Xcode and add a new target (TargetProj)



2--> edit MainProject info from Target

3--> change TargetProj-Info.plist in Info.plist File Property

4--> and change targetProj in Product Name

Tuesday, January 4, 2011

Create Object of class to use as a View

in ChildClass.h
@interface
{
UINavigationController *ng;
id parentController;
}
@property(nonatomic, retain) id ParentController;
@property (nonatomic, retain) IBOutlet UINavigationController *ng;

in ChildClass.m

@synthesize ParentController = parentController;
@synthesize ng;


in ParentClss.m

ChildClass* childObject = [[ChildClass alloc]initWithNibName:@"ChildView" bundle:[NSBundle mainBundle]];
childObject.ParentController=self;
childObject.ng = self.navigationController;
[childObject.view setFrame:CGRectMake(Frame)];
[YourView addSubview:childObject.view];
[self.view sendSubviewToBack:YourView];

Monday, January 3, 2011

UIKeyboardTypeNumberPad missing "return" key

I get the code from Google and modify it for DONE Button in UIKeyboardTypeNumberPad (works in iPhone 4 SDK)

- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField==txtZipCode)
{
[self setViewMovedUp:YES];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(keyboardDidShowOrHide:)
name: UIKeyboardDidShowNotification object:nil];

}
else
{

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
}



}
- (void) keyboardDidShowOrHide : (id) sender {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 427, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setBackgroundImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setBackgroundImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
[tempWindow addSubview:doneButton];


}
-(void)doneButton:(id)sender
{
UIButton *btntmp=sender;
[btntmp removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
[self setViewMovedUp:NO];
[txtZipCode resignFirstResponder];
}