Utility for iPad

Single package which contains Camera, Video, Email, SMS, Date Picker, Time Picker, Custome Picker, Signature capture, Comment box for iPad. You can access these feature with few lines of code.
Download the DKUtility project
Do the following
1)Import the  MobileCoreServices framework
2)Import the following files into your project
DKUtilityController.h
DKUtilityController.m
DKSignature.h
DKSignature.m
3) add the delegate in your view controller.h
<DKUtilityDelegate>
4) create a DKUtilityController object and set its delegate self
DKUtilityController *dkUtility=[[DKUtilityController alloc]init];
 dkUtility.delegate=self;

For open a mail in button action

* add the below line in your button action method
[dkUtility sendEmail:@"message" setRecipient:nil setSubject:@"test"];
*then add the following lines
-(void)openEmail:(MFMailComposeViewController *)mailComposer{
     [self presentViewController:mailComposer animated:YES completion:nil];
}
-(void)dismissEmailView{
    [self dismissViewControllerAnimated:YES completion:nil];
}
For open SMS in button action

 * add the below line in your button action method
 [dkUtility sendSMS:@"message" setRecipient:nil];
*then add the following lines
-(void)openSMS:(MFMessageComposeViewController *)smsComposer{
    [self presentViewController:smsComposer animated:YES completion:nil];
}
-(void)dismissSMSView{
[self dismissViewControllerAnimated:YES completion:nil];
}
For open Date Picker in button action
* add the below line in your button action method
[dkUtility openDatePicker];
*then add the following lines
-(void)setDatePicker:(UIViewController *)date_Picker{
 date_Picker.contentSizeForViewInPopover=CGSizeMake(320, 216);
UIPopoverController *tempPopover=[[UIPopoverController alloc]initWithContentViewController:date_Picker];
 self.popOver=tempPopover;
 [self.popOver presentPopoverFromRect:self.dateButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
  [tempPopover release];
}
-(void)setDate:(NSString *)dateText{
_dateLabel.text=dateText;
}
For open Time Picker in button action
* add the below line in your button action method
[dkUtility openTimePicker];
*then add the following lines
-(void)setTimePicker:(UIViewController *)time_Picker{
  time_Picker.contentSizeForViewInPopover=CGSizeMake(320, 216);
 UIPopoverController *tempPopover=[[UIPopoverController alloc]initWithContentViewController:time_Picker];
self.popOver=tempPopover;
[self.popOver presentPopoverFromRect:self.timeButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[tempPopover release];
}
-(void)setTime:(NSString *)timeText{
_timeLabel.text=timeText;
}
For open Custom Picker in button action

* add the below line in your button action method
 [dkUtility openCustomPickerListView];

*then add the following lines
-(void)setCustomPicker:(UIViewController *)customPickerView{
UIPopoverController *tempPopover=[[UIPopoverController alloc]initWithContentViewController:customPickerView];
self.popOver=tempPopover;
customPickerView.contentSizeForViewInPopover=CGSizeMake(320, 216);
[self.popOver presentPopoverFromRect:self.pickerButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
 [tempPopover release];
}
-(void)selectedPicker:(NSString *)pickerName{
   _pickerListLabel.text=pickerName;
}

For open Signature capture in button action
* add the below line in your button action method
 [dkUtility openSignatureView];

*then add the following lines
-(void)setSignatureController:(UIViewController *)controller{
 controller.contentSizeForViewInPopover=CGSizeMake(320, 216);
 UIPopoverController *tempPopover=[[UIPopoverController alloc]initWithContentViewController:controller];
self.popOver=tempPopover;
 [self.popOver presentPopoverFromRect:self.signBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
 [tempPopover release];
}
-(void)setSignature:(UIView *)signView{
signView.frame=_signView.bounds;
 [_signView addSubview:signView];
[self.popOver dismissPopoverAnimated:YES];
}
For open Comment box in button action

* add the below line in your button action method
[dkUtility openCommentBox];

*then add the following lines

-(void)setComments:(UIViewController *)controller{
UIPopoverController *tempPopover=[[UIPopoverController alloc]initWithContentViewController:controller];
tempPopover.popoverContentSize=CGSizeMake(320, 216);
self.popOver=tempPopover;
controller.contentSizeForViewInPopover=CGSizeMake(320, 216);
 [self.popOver presentPopoverFromRect:self.commentButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[tempPopover release];
}
-(void)setCommentDone:(NSString *)comments{
 self.commentsTxt.text=comments;
 [self.popOver dismissPopoverAnimated:YES];
}
-(void)setCommentCancel
{
 [self.popOver dismissPopoverAnimated:YES];
}

For open CAMERA in button action

* add the below line in your button action method
[dkUtility openCameraForPhoto:YES orVideo:NO];
*then add the following lines

-(void)openCamera:(UIImagePickerController *)imageController{
 UIPopoverController *tempPopover=[[UIPopoverController alloc]initWithContentViewController:imageController];
self.popOver=tempPopover;
 [self.popOver presentPopoverFromRect:self.photoButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
 [tempPopover release];
}
-(void)savePhoto:(NSData *)data{
  _imagePreview.image=[UIImage imageWithData:data];
 [self.popOver dismissPopoverAnimated:YES];
}
For open Video Recorder in button action
* add the below line in your button action method
 [dkUtility openCameraForPhoto:NO orVideo:YES];
*then add the following lines
-(void)saveVideo:(NSData *)data{
  if([[NSFileManager defaultManager]fileExistsAtPath:self.fileName]){
     NSError *error;
     [[NSFileManager defaultManager]removeItemAtPath:self.fileName error:&error];  
}
else{
    NSArray *array=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *path=[array objectAtIndex:0];
    NSString *tempfileName=[path stringByAppendingPathComponent:VIDEOFILE];
    [data writeToFile:tempfileName atomically:YES];
     self.fileName=tempfileName;
   MPMoviePlayerController *controller=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL    fileURLWithPath:tempfileName]];
   UIImage *preview=[controller thumbnailImageAtTime:0.5      timeOption:MPMovieTimeOptionNearestKeyFrame];
   [self.videoPreview setImage:preview forState:UIControlStateNormal];
   [controller release];
  [self.popOver dismissPopoverAnimated:YES];
 }
}
-(void)movieFinish:(NSNotification *)notification{
 [self.popOver dismissPopoverAnimated:YES];
 MPMoviePlayerViewController *moviePlayer=[notification object];
 [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
}

Comments