forked from npctech/Tattle-UI-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTattleControl.m
More file actions
547 lines (471 loc) · 21.8 KB
/
Copy pathTattleControl.m
File metadata and controls
547 lines (471 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
//
// TattleControl.m
/*
Copyright (c) 2014 TattleUI (http://www.npcompete.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import "TattleControl.h"
#import "CommonMacro.h"
#import "SnapShotView.h"
#import "TFileManager.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import "TPopupView.h"
#define SquareButtonSize 40
#define DefaultSpotImageColor [UIColor colorWithRed:30.0/255.0 green:153.0/255.0 blue:246.0/255.0 alpha:0.75];
typedef enum SpotImageSizeFactor : NSUInteger {
SpotImageSizeFactorCornerLineWidth = 12,/* for iPhone, iPad = 2 * iPhone...*/
SpotImageSizeFactorCornerLineThickness = 5,
SpotImageSizeFactorCenterLineWidth = 8,
SpotImageSizeFactorCenterLineThickness = 1,
SpotImageSizeFactorCenterRadius = 4
}SpotImageSizeFactor;
NSString const *kMimeTypeAudio = @"audio/aac";
NSString const *kMimeTypeImage = @"image/png";
NSString const *kAudioPrefix = @"audio";
NSString const *kImagePrefix = @"image";
NSString const *kEmailSentResult = @"Result";
NSString const *kEmailSentMessage = @"Mail Sent Successfully";
NSString const *kOKButtonTitle = @"OK";
NSInteger const kMailSuccess = 1008;
@interface TattleControl ()<MFMailComposeViewControllerDelegate>
@property (nonatomic,strong) UIButton *snapShotBtn;
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic,strong) UIImage *spotImage;
@property (nonatomic,strong) UIColor *spotImageColor;
@property (nonatomic, strong) id presentedVC;
@property (nonatomic,strong) TPopupView *confirmationView;
@property (nonatomic, strong) NSMutableArray *emailRecipients, *eMailCCRecipients;
@property (nonatomic, strong) NSString *emailSubject;
@end
@implementation TattleControl
#pragma mark - Control Creation and Assign Frame
- (void)assignButtonWithFrame:(CGRect)frame
{
self.frame = CGRectMake(100,200, frame.size.width, frame.size.height);
self.snapShotBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.snapShotBtn.frame = frame;
[self.snapShotBtn addTarget:self action:@selector(snapButtonFired:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.snapShotBtn];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panning:)];
[self addGestureRecognizer:panGesture];
}
#pragma mark - Tattle Shared Control
+(TattleControl*)sharedControl
{
static dispatch_once_t predicate = 0;
static TattleControl *sharedInstance = nil;
dispatch_once(&predicate, ^{
sharedInstance = [[self alloc] init];
[sharedInstance assignButtonWithFrame:CGRectMake(0, 0,resizeDependsDevice(SquareButtonSize),resizeDependsDevice(SquareButtonSize))];
sharedInstance.spotImageColor = DefaultSpotImageColor;
sharedInstance.backgroundColor = [UIColor clearColor];
sharedInstance.emailRecipients = [NSMutableArray array];
sharedInstance.eMailCCRecipients = [NSMutableArray array];
});
return sharedInstance;
}
#pragma mark - Spot Button action.
-(void)snapButtonFired:(UIButton*)snapButton
{
NSLog(@"Snap button Fired");
[snapButton setHidden:YES];
[self setNeedsDisplay];
[[SnapShotView sharedView] assignBackgroundColorWithImage:[self getScreenShotImageWithOutStatusBar]];
[self.window insertSubview:[[SnapShotView sharedView] getBaseView] aboveSubview:self];
[[SnapShotView sharedView] addScribbleControllToSnapView];
[self addPopUpAnimationToView:[SnapShotView sharedView] isPopIn:YES];
}
#pragma mark - Enable Screen shot Control to this Window
-(void)enableTattleToWindow:(UIWindow*)baseWindow
{
self.window = baseWindow;
[baseWindow addSubview:self];
}
-(void)changeSpotImageColor:(UIColor*)spotColor
{
self.spotImageColor = spotColor;
}
#pragma mark - Email Configuration
-(void)addRecipientMailId:(NSString*)recipientMailId
{
if (recipientMailId)
[self.emailRecipients addObject:recipientMailId];
}
-(void)addCCMailId:(NSString*)ccMailId
{
if (ccMailId)
[self.eMailCCRecipients addObject:ccMailId];
}
-(void)assignMailSubject:(NSString*)subject
{
if (subject)
self.emailSubject = subject;
}
-(void)assignRecipientEmailId:(NSString*)toEmailId withCCId:(NSString*)ccId emailSubject:(NSString*)subject
{
[self addRecipientMailId:toEmailId];
[self addCCMailId:ccId];
[self assignMailSubject:subject];
}
#pragma mark - Change Scribble color
-(void)setScribbleColor:(UIColor*)scribbleColor
{
[[SnapShotView sharedView] changeScribbleColor:scribbleColor];
}
#pragma mark - Set Movable Control Background Color
-(void)setMovableControlBackgroundColor:(UIColor*)backgroundColor
{
[[SnapShotView sharedView] setMovableControlBackgroundColor:backgroundColor];
}
-(void)setMovableControlBackgroundColor:(UIColor *)backgroundColor withAlpha:(CGFloat)alpha
{
[[SnapShotView sharedView] setMovableControlBackgroundColor:backgroundColor withAlpha:alpha];
}
#pragma mark - Panning Handle
-(CGPoint)checkViewOutOfBounds:(UIView*)snapView withBaseView:(UIView*)baseView
{
NSLog(@"Snap view Frame %f %f",snapView.center.x,snapView.center.y);
CGPoint leftTopCorner = CGPointMake( snapView.frame.size.width/2, snapView.frame.size.height/2);
CGPoint rightTopCorner = CGPointMake( baseView.frame.size.width - snapView.frame.size.width/2, snapView.frame.size.height/2);
CGPoint leftBottomCornor = CGPointMake( snapView.frame.size.width/2, baseView.frame.size.height - snapView.frame.size.height/2);
CGPoint rightBottomCornor = CGPointMake( baseView.frame.size.width - snapView.frame.size.width/2, baseView.frame.size.height - snapView.frame.size.height/2);
if ( snapView.center.x < leftTopCorner.x && snapView.center.y < leftTopCorner.y)
return leftTopCorner;
else if ( snapView.center.x > rightTopCorner.x && snapView.center.y < rightTopCorner.y)
return rightTopCorner;
else if ( snapView.center.x < leftBottomCornor.x && snapView.center.y > leftBottomCornor.y)
return leftBottomCornor;
else if (snapView.center.x > rightBottomCornor.x && snapView.center.y > rightBottomCornor.y )
return rightBottomCornor;
else if ( snapView.center.x < leftTopCorner.x)
return CGPointMake(leftTopCorner.x, snapView.center.y);
else if (snapView.center.y < leftTopCorner.y)
return CGPointMake(snapView.center.x,leftTopCorner.y);
else if (snapView.center.x > rightTopCorner.x )
return CGPointMake(rightTopCorner.x, snapView.center.y);
else if (snapView.center.y < rightTopCorner.y)
return CGPointMake(snapView.center.x,rightTopCorner.y);
else if ( snapView.center.x < leftBottomCornor.x )
return CGPointMake(leftBottomCornor.x, snapView.center.y);
else if ( snapView.center.y > leftBottomCornor.y)
return CGPointMake(snapView.center.x, leftBottomCornor.y);
else if ( snapView.center.x > rightBottomCornor.x)
return CGPointMake(rightBottomCornor.x, snapView.center.y);
else if ( snapView.center.y > rightBottomCornor.y)
return CGPointMake(snapView.center.x, rightBottomCornor.y);
else
return CGPointZero;
}
-(void)panning:(UIPanGestureRecognizer*)gesture
{
CGPoint translation = [gesture translationInView:self.window];
CGPoint finalTranslation = CGPointZero;
gesture.view.center = CGPointMake(gesture.view.center.x + translation.x,
gesture.view.center.y + translation.y);
if (gesture.state == UIGestureRecognizerStateCancelled ||
gesture.state == UIGestureRecognizerStateFailed ||
gesture.state == UIGestureRecognizerStateEnded)
{
if (CGPointEqualToPoint((finalTranslation =[self checkViewOutOfBounds:gesture.view withBaseView:self.window]),CGPointZero))
return;
else
gesture.view.center = finalTranslation;
}
[gesture setTranslation:CGPointMake(0, 0) inView:self.window];
}
#pragma mark - Set Spot Image
-(void)setSpotButtonImage:(UIImage*)image
{
self.spotImage = image;
if (self.snapShotBtn)
[self.snapShotBtn setBackgroundImage:self.spotImage forState:UIControlStateNormal];
}
#pragma mark - Spot Image drawing
-(void)drawLineFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint forContext:(CGContextRef)context
{
CGContextMoveToPoint(context, fromPoint.x,fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x,toPoint.y);
CGContextStrokePath(context);
}
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
if (!self.spotImage)
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, self.spotImageColor.CGColor);
//Left Corner
CGContextSetLineWidth(context,resizeDependsDevice(SpotImageSizeFactorCornerLineThickness));
[self drawLineFromPoint:CGPointMake(0, 0) toPoint:CGPointMake(0, resizeDependsDevice(SpotImageSizeFactorCornerLineWidth)) forContext:context];
[self drawLineFromPoint:CGPointMake(0,0) toPoint:CGPointMake(resizeDependsDevice(SpotImageSizeFactorCornerLineWidth), 0) forContext:context];
//Right Corner
[self drawLineFromPoint:CGPointMake(self.frame.size.width, 0) toPoint:CGPointMake(self.frame.size.width - resizeDependsDevice(SpotImageSizeFactorCornerLineWidth), 0) forContext:context];
[self drawLineFromPoint:CGPointMake(self.frame.size.width,0) toPoint:CGPointMake(self.frame.size.width,resizeDependsDevice(SpotImageSizeFactorCornerLineWidth)) forContext:context];
//Bottom Left corner
[self drawLineFromPoint:CGPointMake(0, self.frame.size.height) toPoint:CGPointMake(0, self.frame.size.height -resizeDependsDevice(SpotImageSizeFactorCornerLineWidth)) forContext:context];
[self drawLineFromPoint:CGPointMake(0, self.frame.size.height) toPoint:CGPointMake(resizeDependsDevice(SpotImageSizeFactorCornerLineWidth), self.frame.size.height) forContext:context];
//Botto Right Corner
[self drawLineFromPoint:CGPointMake(self.frame.size.width, self.frame.size.height) toPoint:CGPointMake(self.frame.size.width - resizeDependsDevice(SpotImageSizeFactorCornerLineWidth), self.frame.size.height) forContext:context];
[self drawLineFromPoint:CGPointMake(self.frame.size.width, self.frame.size.height) toPoint:CGPointMake(self.frame.size.width,self.frame.size.height - resizeDependsDevice(SpotImageSizeFactorCornerLineWidth)) forContext:context];
CGContextSetLineWidth(context, resizeDependsDevice(SpotImageSizeFactorCenterLineThickness));
[self drawLineFromPoint:CGPointMake(self.frame.size.width/2, 0) toPoint:CGPointMake(self.frame.size.width/2, resizeDependsDevice(SpotImageSizeFactorCenterLineWidth)) forContext:context];
[self drawLineFromPoint:CGPointMake(self.frame.size.width/2, self.frame.size.height) toPoint:CGPointMake(self.frame.size.width/2,self.frame.size.height-resizeDependsDevice(SpotImageSizeFactorCenterLineWidth)) forContext:context];
[self drawLineFromPoint:CGPointMake(0, self.frame.size.height/2) toPoint:CGPointMake(resizeDependsDevice(SpotImageSizeFactorCenterLineWidth), self.frame.size.height/2) forContext:context];
[self drawLineFromPoint:CGPointMake(self.frame.size.width, self.frame.size.height/2) toPoint:CGPointMake(self.frame.size.width - resizeDependsDevice(SpotImageSizeFactorCenterLineWidth), self.frame.size.height/2) forContext:context];
CGContextAddArc(context, self.frame.size.width/2,self.frame.size.height/2, resizeDependsDevice(SpotImageSizeFactorCenterRadius), 0, 360, 0);
CGContextStrokePath(context);
CGImageRef rawMask = CGBitmapContextCreateImage(context);
self.spotImage = [UIImage imageWithCGImage:rawMask];
if (self.snapShotBtn)
[self.snapShotBtn setBackgroundImage:self.spotImage forState:UIControlStateNormal];
CGImageRelease(rawMask);
}
}
#pragma mark - Remove Snap View
-(void)removeSnapShotView
{
[[SnapShotView sharedView] removeFromWindow];
}
#pragma mark - Animation Delegate - only for PopUp
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self removeSnapShotView];
[self.snapShotBtn setHidden:NO];
}
#pragma mark - Popup & Popin animation
- (void) addPopUpAnimationToView:(UIView*)view isPopIn:(BOOL)popIn
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
CATransform3D scale1 = CATransform3DMakeScale(0.2, 0.2, 1);
CATransform3D scale11 = CATransform3DMakeScale(0.5, 0.5, 1);
CATransform3D scale2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D scale3 = CATransform3DMakeScale(0.9, 0.9, 1);
CATransform3D scale4 = CATransform3DMakeScale(1.0, 1.0, 1);
NSArray *frameValues = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:scale1],
[NSValue valueWithCATransform3D:scale11],
[NSValue valueWithCATransform3D:scale2],
[NSValue valueWithCATransform3D:scale3],
[NSValue valueWithCATransform3D:scale4],
nil];
NSArray *frameTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.1],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:0.9],
[NSNumber numberWithFloat:1.0],
nil];
animation.duration = 0.8;
if (popIn)
{
[animation setValues:frameValues];
[animation setKeyTimes:frameTimes];
animation.fillMode = kCAFillModeForwards;
}
else
{
[animation setValues:[[frameValues reverseObjectEnumerator] allObjects]];
[animation setKeyTimes:frameTimes];
animation.fillMode = kCAFillModeRemoved;
animation.delegate = self;
}
[view.layer addAnimation:animation forKey:@"popup"];
}
#pragma mark - Cancel Button Action
- (void) showConfirmationView {
if (!self.confirmationView)
{
if (IS_IPAD)
self.confirmationView = [[[NSBundle mainBundle] loadNibNamed:@"TPopupView" owner:nil options:nil] lastObject];
else
self.confirmationView = [[[NSBundle mainBundle] loadNibNamed:@"TPopupView" owner:nil options:nil] firstObject];
__weak typeof(self) weakSelf = self;
self.confirmationView.okActionBlock = ^{
NSLog(@"Ok Button Tapped");
[weakSelf.confirmationView removeFromSuperview];
[weakSelf showWithAnimation];
};
self.confirmationView.cancelActionBlock = ^{
NSLog(@"Cancel button Tapped");
[weakSelf.confirmationView hideWithAnimation];
};
}
[[[SnapShotView sharedView] getBaseView] addSubview:self.confirmationView];
[self.confirmationView showWithAnimation];
}
-(void)showWithAnimation
{
[self addPopUpAnimationToView:[SnapShotView sharedView] isPopIn:NO];
}
-(void)closeButtonFired:(UIButton*)closeBtn
{
[self showConfirmationView];
}
#pragma mark - Getting Device scale
-(CGFloat)getScale
{
CGFloat scale = 1.0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
scale = [[UIScreen mainScreen] scale];
}
#endif
return scale;
}
#pragma mark - Screen shot from view's layer
-(UIImage*)takeScreenShotImageForView:(UIView *)baseView
{
return [self takeScreenShotImageForView:baseView withScale:1.0];
}
-(UIImage*)takeScreenShotImageForView:(UIView *)baseView withScale:(CGFloat)scale
{
CGSize size = CGSizeMake(baseView.layer.frame.size.width*scale, baseView.layer.frame.size.height*scale);
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(iOS7_0))
[baseView drawViewHierarchyInRect:baseView.frame afterScreenUpdates:YES];
else
[baseView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return (!image) ? nil : image;
}
#pragma mark remove the status bar from screen shot image
-(UIImage *)getScreenShotImageWithOutStatusBar
{
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
CGFloat scale = [self getScale];
UIImage *image = [self takeScreenShotImageForView:window withScale:scale];
CGImageRef tmpImgRef = image.CGImage;
CGImageRef topImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, (scale*20), image.size.width, image.size.height-(scale*20)));
UIImage *topImage = [UIImage imageWithCGImage:topImgRef];
CGImageRelease(topImgRef);
return topImage;
}
#pragma mark get PresentedView controller
-(UIViewController*)getVisibleViewControllerFrom:(UIViewController *) vc
{
return ([vc presentedViewController]) ? [vc presentedViewController]: nil;
}
#pragma mark send screen shot
-(void)sendScreenShotAudioFiles
{
if(![MFMailComposeViewController canSendMail])
return;
[self removeSnapShotView];
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc]init];
[mailComposer setMailComposeDelegate:self];
//Attach audios
NSInteger i = 0;
NSArray *audios = [[TFileManager sharedFileManager] getRecordedAudios];
for (NSString *path in audios)
{
i++;
[mailComposer addAttachmentData:[NSData dataWithContentsOfFile:path] mimeType:(NSString*)kMimeTypeAudio fileName:[NSString stringWithFormat:@"%@%ld", kAudioPrefix, (long)i]];
}
//Set subject
if(self.emailSubject)
[mailComposer setSubject:self.emailSubject];
//Set email recipients
if(self.emailRecipients)
[mailComposer setToRecipients:self.emailRecipients];
//Set email cc recipients
if(self.eMailCCRecipients)
[mailComposer setCcRecipients:self.eMailCCRecipients];
//Attach screen shots
NSArray *screenShots = [[TFileManager sharedFileManager] getScreenShots];
for (NSString *path in screenShots)
{
i++;
[mailComposer addAttachmentData:[NSData dataWithContentsOfFile:path] mimeType:(NSString*)kMimeTypeImage fileName:[NSString stringWithFormat:@"%@%ld", kImagePrefix, (long)i]];
}
self.presentedVC = [self getVisibleViewControllerFrom:self.window.rootViewController];
if(self.presentedVC)
{
//Hold already presented vc and present it once mailcomposer vc is dismissed
[self.window.rootViewController dismissViewControllerAnimated:NO completion:^{
[self.window.rootViewController presentViewController:mailComposer animated:YES completion:nil];
}];
}
else
{
[self.window.rootViewController presentViewController:mailComposer animated:YES completion:nil];
}
}
#pragma mark dismiss mail composer vc and present the presented vc if the root vc already had presented vc
-(void)dismissMailVCAndPresentAlreadyPresnetedVC
{
if(self.presentedVC)
{
[self.window.rootViewController dismissViewControllerAnimated:NO completion:^{
[self.window.rootViewController presentViewController:self.presentedVC animated:NO completion:^{
[self.snapShotBtn setHidden:NO];
self.presentedVC = nil;
}];
}];
}
else
{
[self.window.rootViewController dismissViewControllerAnimated:YES completion:^{
[self.snapShotBtn setHidden:NO];
}];
}
}
#pragma mark mail composer delegate
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
[self clearAudiosAndScreenShots];
break;
case MFMailComposeResultSaved:
[self clearAudiosAndScreenShots];
break;
case MFMailComposeResultSent:
{
[self clearAudiosAndScreenShots];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:(NSString*)kEmailSentResult message:(NSString*)kEmailSentMessage delegate:self cancelButtonTitle:(NSString*)kOKButtonTitle otherButtonTitles:nil, nil];
[alert setTag:kMailSuccess];
[alert show];
return;
}
break;
case MFMailComposeResultFailed:
break;
default:
[self clearAudiosAndScreenShots];
break;
}
[self dismissMailVCAndPresentAlreadyPresnetedVC];
}
#pragma mark clear audios and screen shots
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag == kMailSuccess)
{
[self dismissMailVCAndPresentAlreadyPresnetedVC];
}
}
#pragma mark clear audios and screen shots
-(void)clearAudiosAndScreenShots
{
[[TFileManager sharedFileManager] clearAllAudios];
[[TFileManager sharedFileManager] clearAllScreenShots];
}
@end