Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.13 KB | None | 0 0
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9.  
  10. http://www.apache.org/licenses/LICENSE-2.0
  11.  
  12. Unless required by applicable law or agreed to in writing,
  13. software distributed under the License is distributed on an
  14. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. KIND, either express or implied. See the License for the
  16. specific language governing permissions and limitations
  17. under the License.
  18. */
  19.  
  20. #import "CDVCapture.h"
  21. #import "CDVFile.h"
  22. #import <Cordova/CDVAvailability.h>
  23.  
  24. #define kW3CMediaFormatHeight @"height"
  25. #define kW3CMediaFormatWidth @"width"
  26. #define kW3CMediaFormatCodecs @"codecs"
  27. #define kW3CMediaFormatBitrate @"bitrate"
  28. #define kW3CMediaFormatDuration @"duration"
  29. #define kW3CMediaModeType @"type"
  30.  
  31. @implementation NSBundle (PluginExtensions)
  32.  
  33. + (NSBundle*) pluginBundle:(CDVPlugin*)plugin {
  34. NSBundle* bundle = [NSBundle bundleWithPath: [[NSBundle mainBundle] pathForResource:NSStringFromClass([plugin class]) ofType: @"bundle"]];
  35. return bundle;
  36. }
  37. @end
  38.  
  39. #define PluginLocalizedString(plugin, key, comment) [[NSBundle pluginBundle:(plugin)] localizedStringForKey:(key) value:nil table:nil]
  40.  
  41. @implementation CDVImagePicker
  42.  
  43. @synthesize quality;
  44. @synthesize callbackId;
  45. @synthesize mimeType;
  46.  
  47. - (uint64_t)accessibilityTraits
  48. {
  49. NSString* systemVersion = [[UIDevice currentDevice] systemVersion];
  50.  
  51. if (([systemVersion compare:@"4.0" options:NSNumericSearch] != NSOrderedAscending)) { // this means system version is not less than 4.0
  52. return UIAccessibilityTraitStartsMediaSession;
  53. }
  54.  
  55. return UIAccessibilityTraitNone;
  56. }
  57.  
  58. - (BOOL)prefersStatusBarHidden {
  59. return YES;
  60. }
  61.  
  62. - (UIViewController*)childViewControllerForStatusBarHidden {
  63. return nil;
  64. }
  65.  
  66. - (void)viewWillAppear:(BOOL)animated {
  67. SEL sel = NSSelectorFromString(@"setNeedsStatusBarAppearanceUpdate");
  68. if ([self respondsToSelector:sel]) {
  69. [self performSelector:sel withObject:nil afterDelay:0];
  70. }
  71.  
  72. [super viewWillAppear:animated];
  73. }
  74.  
  75. @end
  76.  
  77. @implementation CDVCapture
  78. @synthesize inUse;
  79.  
  80. - (void)pluginInitialize
  81. {
  82. self.inUse = NO;
  83. }
  84.  
  85. - (void)captureAudio:(CDVInvokedUrlCommand*)command
  86. {
  87. NSString* callbackId = command.callbackId;
  88. NSDictionary* options = [command argumentAtIndex:0];
  89.  
  90. if ([options isKindOfClass:[NSNull class]]) {
  91. options = [NSDictionary dictionary];
  92. }
  93.  
  94. NSNumber* duration = [options objectForKey:@"duration"];
  95. // the default value of duration is 0 so use nil (no duration) if default value
  96. if (duration) {
  97. duration = [duration doubleValue] == 0 ? nil : duration;
  98. }
  99. CDVPluginResult* result = nil;
  100.  
  101. if (NSClassFromString(@"AVAudioRecorder") == nil) {
  102. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
  103. } else if (self.inUse == YES) {
  104. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_APPLICATION_BUSY];
  105. } else {
  106. // all the work occurs here
  107. CDVAudioRecorderViewController* audioViewController = [[CDVAudioRecorderViewController alloc] initWithCommand:self duration:duration callbackId:callbackId];
  108.  
  109. // Now create a nav controller and display the view...
  110. CDVAudioNavigationController* navController = [[CDVAudioNavigationController alloc] initWithRootViewController:audioViewController];
  111.  
  112. self.inUse = YES;
  113.  
  114. [self.viewController presentViewController:navController animated:YES completion:nil];
  115. }
  116.  
  117. if (result) {
  118. [self.commandDelegate sendPluginResult:result callbackId:callbackId];
  119. }
  120. }
  121.  
  122. - (void)captureImage:(CDVInvokedUrlCommand*)command
  123. {
  124. NSString* callbackId = command.callbackId;
  125. NSDictionary* options = [command argumentAtIndex:0];
  126.  
  127. if ([options isKindOfClass:[NSNull class]]) {
  128. options = [NSDictionary dictionary];
  129. }
  130.  
  131. // options could contain limit and mode neither of which are supported at this time
  132. // taking more than one picture (limit) is only supported if provide own controls via cameraOverlayView property
  133. // can support mode in OS
  134.  
  135. if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  136. NSLog(@"Capture.imageCapture: camera not available.");
  137. CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
  138. [self.commandDelegate sendPluginResult:result callbackId:callbackId];
  139. } else {
  140. if (pickerController == nil) {
  141. pickerController = [[CDVImagePicker alloc] init];
  142. }
  143.  
  144. [self showAlertIfAccessProhibited];
  145. pickerController.delegate = self;
  146. pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  147. pickerController.allowsEditing = NO;
  148. if ([pickerController respondsToSelector:@selector(mediaTypes)]) {
  149. // iOS 3.0
  150. pickerController.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage, nil];
  151. }
  152.  
  153. /*if ([pickerController respondsToSelector:@selector(cameraCaptureMode)]){
  154. // iOS 4.0
  155. pickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
  156. pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
  157. pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
  158. }*/
  159. // CDVImagePicker specific property
  160. pickerController.callbackId = callbackId;
  161. pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
  162. [self.viewController presentViewController:pickerController animated:YES completion:nil];
  163. }
  164. }
  165.  
  166. /* Process a still image from the camera.
  167. * IN:
  168. * UIImage* image - the UIImage data returned from the camera
  169. * NSString* callbackId
  170. */
  171. - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId
  172. {
  173. CDVPluginResult* result = nil;
  174.  
  175. // save the image to photo album
  176. UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
  177.  
  178. NSData* data = nil;
  179. if (mimeType && [mimeType isEqualToString:@"image/png"]) {
  180. data = UIImagePNGRepresentation(image);
  181. } else {
  182. data = UIImageJPEGRepresentation(image, 0.5);
  183. }
  184.  
  185. // write to temp directory and return URI
  186. NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath]; // use file system temporary directory
  187. NSError* err = nil;
  188. NSFileManager* fileMgr = [[NSFileManager alloc] init];
  189.  
  190. // generate unique file name
  191. NSString* filePath;
  192. int i = 1;
  193. do {
  194. filePath = [NSString stringWithFormat:@"%@/photo_%03d.jpg", docsPath, i++];
  195. } while ([fileMgr fileExistsAtPath:filePath]);
  196.  
  197. if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
  198. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageToErrorObject:CAPTURE_INTERNAL_ERR];
  199. if (err) {
  200. NSLog(@"Error saving image: %@", [err localizedDescription]);
  201. }
  202. } else {
  203. // create MediaFile object
  204.  
  205. NSDictionary* fileDict = [self getMediaDictionaryFromPath:filePath ofType:mimeType];
  206. NSArray* fileArray = [NSArray arrayWithObject:fileDict];
  207.  
  208. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
  209. }
  210.  
  211. return result;
  212. }
  213.  
  214. - (void)captureVideo:(CDVInvokedUrlCommand*)command
  215. {
  216. NSString* callbackId = command.callbackId;
  217. NSDictionary* options = [command argumentAtIndex:0];
  218.  
  219. if ([options isKindOfClass:[NSNull class]]) {
  220. options = [NSDictionary dictionary];
  221. }
  222.  
  223. // options could contain limit, duration and mode
  224. // taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property
  225. NSNumber* duration = [options objectForKey:@"duration"];
  226. NSString* mediaType = nil;
  227.  
  228. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  229. // there is a camera, it is available, make sure it can do movies
  230. pickerController = [[CDVImagePicker alloc] init];
  231.  
  232. NSArray* types = nil;
  233. if ([UIImagePickerController respondsToSelector:@selector(availableMediaTypesForSourceType:)]) {
  234. types = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
  235. // NSLog(@"MediaTypes: %@", [types description]);
  236.  
  237. if ([types containsObject:(NSString*)kUTTypeMovie]) {
  238. mediaType = (NSString*)kUTTypeMovie;
  239. } else if ([types containsObject:(NSString*)kUTTypeVideo]) {
  240. mediaType = (NSString*)kUTTypeVideo;
  241. }
  242. }
  243. }
  244. if (!mediaType) {
  245. // don't have video camera return error
  246. NSLog(@"Capture.captureVideo: video mode not available.");
  247. CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
  248. [self.commandDelegate sendPluginResult:result callbackId:callbackId];
  249. pickerController = nil;
  250. } else {
  251. [self showAlertIfAccessProhibited];
  252.  
  253. pickerController.delegate = self;
  254. pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  255. pickerController.allowsEditing = NO;
  256. // iOS 3.0
  257. pickerController.mediaTypes = [NSArray arrayWithObjects:mediaType, nil];
  258.  
  259. if ([mediaType isEqualToString:(NSString*)kUTTypeMovie]){
  260. if (duration) {
  261. pickerController.videoMaximumDuration = [duration doubleValue];
  262. }
  263. //NSLog(@"pickerController.videoMaximumDuration = %f", pickerController.videoMaximumDuration);
  264. }
  265.  
  266. // iOS 4.0
  267. if ([pickerController respondsToSelector:@selector(cameraCaptureMode)]) {
  268. pickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
  269.  
  270. NSNumber* quality = [options objectForKey:@"ios_quality"];
  271.  
  272. if ([quality isEqual:@("compression_none_640x480")]){ //Compression none
  273. pickerController.videoQuality = UIImagePickerControllerQualityType640x480;
  274. }
  275. else if ([quality isEqual:@("compression_none_960x540")]){ //Compression none
  276. pickerController.videoQuality = UIImagePickerControllerQualityTypeIFrame960x540;
  277. }
  278. else if ([quality isEqual:@("compression_none_1280x720")]){ //Compression none
  279. pickerController.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
  280. }
  281. else if ([quality isEqual:@("high")]){ //Compression low
  282. pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
  283. }
  284. else if ([quality isEqual:@("medium")]){ //Compression medium
  285. pickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
  286. }
  287. else if ([quality isEqual:@("low")]){ //strongest compression, resolution 192x144
  288. pickerController.videoQuality = UIImagePickerControllerQualityTypeLow;
  289. }
  290.  
  291. // pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
  292. // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
  293. // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
  294. }
  295.  
  296. // iOS 4.0
  297. // if ([pickerController respondsToSelector:@selector(cameraCaptureMode)]) {
  298. // pickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
  299. // // pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
  300. // // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
  301. // // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
  302. // }
  303. // CDVImagePicker specific property
  304. pickerController.callbackId = callbackId;
  305. pickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
  306. [self.viewController presentViewController:pickerController animated:YES completion:nil];
  307. }
  308. }
  309.  
  310. - (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId
  311. {
  312. // save the movie to photo album (only avail as of iOS 3.1)
  313.  
  314. /* don't need, it should automatically get saved
  315. NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath));
  316. if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) {
  317. NSLog(@"try to save movie");
  318. UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil);
  319. NSLog(@"finished saving movie");
  320. }*/
  321. // create MediaFile object
  322. NSDictionary* fileDict = [self getMediaDictionaryFromPath:moviePath ofType:nil];
  323. NSArray* fileArray = [NSArray arrayWithObject:fileDict];
  324.  
  325. return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
  326. }
  327.  
  328. - (void)showAlertIfAccessProhibited
  329. {
  330. if (![self hasCameraAccess]) {
  331. [self showPermissionsAlert];
  332. }
  333. }
  334.  
  335. - (BOOL)hasCameraAccess
  336. {
  337. AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  338.  
  339. return status != AVAuthorizationStatusDenied && status != AVAuthorizationStatusRestricted;
  340. }
  341.  
  342. - (void)showPermissionsAlert
  343. {
  344. __weak CDVCapture* weakSelf = self;
  345. dispatch_async(dispatch_get_main_queue(), ^{
  346. [[[UIAlertView alloc] initWithTitle:[[NSBundle mainBundle]
  347. objectForInfoDictionaryKey:@"CFBundleDisplayName"]
  348. message:NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.", nil)
  349. delegate:weakSelf
  350. cancelButtonTitle:NSLocalizedString(@"OK", nil)
  351. otherButtonTitles:NSLocalizedString(@"Settings", nil), nil] show];
  352. });
  353. }
  354.  
  355. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  356. {
  357. if (buttonIndex == 1) {
  358. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  359. }
  360.  
  361. CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_PERMISSION_DENIED];
  362.  
  363. [[pickerController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
  364. [self.commandDelegate sendPluginResult:result callbackId:pickerController.callbackId];
  365. pickerController = nil;
  366. self.inUse = NO;
  367. }
  368.  
  369. - (void)getMediaModes:(CDVInvokedUrlCommand*)command
  370. {
  371. // NSString* callbackId = [command argumentAtIndex:0];
  372. // NSMutableDictionary* imageModes = nil;
  373. NSArray* imageArray = nil;
  374. NSArray* movieArray = nil;
  375. NSArray* audioArray = nil;
  376.  
  377. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  378. // there is a camera, find the modes
  379. // can get image/jpeg or image/png from camera
  380.  
  381. /* can't find a way to get the default height and width and other info
  382. * for images/movies taken with UIImagePickerController
  383. */
  384. NSDictionary* jpg = [NSDictionary dictionaryWithObjectsAndKeys:
  385. [NSNumber numberWithInt:0], kW3CMediaFormatHeight,
  386. [NSNumber numberWithInt:0], kW3CMediaFormatWidth,
  387. @"image/jpeg", kW3CMediaModeType,
  388. nil];
  389. NSDictionary* png = [NSDictionary dictionaryWithObjectsAndKeys:
  390. [NSNumber numberWithInt:0], kW3CMediaFormatHeight,
  391. [NSNumber numberWithInt:0], kW3CMediaFormatWidth,
  392. @"image/png", kW3CMediaModeType,
  393. nil];
  394. imageArray = [NSArray arrayWithObjects:jpg, png, nil];
  395.  
  396. if ([UIImagePickerController respondsToSelector:@selector(availableMediaTypesForSourceType:)]) {
  397. NSArray* types = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
  398.  
  399. if ([types containsObject:(NSString*)kUTTypeMovie]) {
  400. NSDictionary* mov = [NSDictionary dictionaryWithObjectsAndKeys:
  401. [NSNumber numberWithInt:0], kW3CMediaFormatHeight,
  402. [NSNumber numberWithInt:0], kW3CMediaFormatWidth,
  403. @"video/quicktime", kW3CMediaModeType,
  404. nil];
  405. movieArray = [NSArray arrayWithObject:mov];
  406. }
  407. }
  408. }
  409. NSDictionary* modes = [NSDictionary dictionaryWithObjectsAndKeys:
  410. imageArray ? (NSObject*) imageArray:[NSNull null], @"image",
  411. movieArray ? (NSObject*) movieArray:[NSNull null], @"video",
  412. audioArray ? (NSObject*) audioArray:[NSNull null], @"audio",
  413. nil];
  414.  
  415. NSData* jsonData = [NSJSONSerialization dataWithJSONObject:modes options:0 error:nil];
  416. NSString* jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  417.  
  418. NSString* jsString = [NSString stringWithFormat:@"navigator.device.capture.setSupportedModes(%@);", jsonStr];
  419. [self.commandDelegate evalJs:jsString];
  420. }
  421.  
  422. - (void)getFormatData:(CDVInvokedUrlCommand*)command
  423. {
  424. NSString* callbackId = command.callbackId;
  425. // existence of fullPath checked on JS side
  426. NSString* fullPath = [command argumentAtIndex:0];
  427. // mimeType could be null
  428. NSString* mimeType = nil;
  429.  
  430. if ([command.arguments count] > 1) {
  431. mimeType = [command argumentAtIndex:1];
  432. }
  433. BOOL bError = NO;
  434. CDVCaptureError errorCode = CAPTURE_INTERNAL_ERR;
  435. CDVPluginResult* result = nil;
  436.  
  437. if (!mimeType || [mimeType isKindOfClass:[NSNull class]]) {
  438. // try to determine mime type if not provided
  439. id command = [self.commandDelegate getCommandInstance:@"File"];
  440. bError = !([command isKindOfClass:[CDVFile class]]);
  441. if (!bError) {
  442. CDVFile* cdvFile = (CDVFile*)command;
  443. mimeType = [cdvFile getMimeTypeFromPath:fullPath];
  444. if (!mimeType) {
  445. // can't do much without mimeType, return error
  446. bError = YES;
  447. errorCode = CAPTURE_INVALID_ARGUMENT;
  448. }
  449. }
  450. }
  451. if (!bError) {
  452. // create and initialize return dictionary
  453. NSMutableDictionary* formatData = [NSMutableDictionary dictionaryWithCapacity:5];
  454. [formatData setObject:[NSNull null] forKey:kW3CMediaFormatCodecs];
  455. [formatData setObject:[NSNumber numberWithInt:0] forKey:kW3CMediaFormatBitrate];
  456. [formatData setObject:[NSNumber numberWithInt:0] forKey:kW3CMediaFormatHeight];
  457. [formatData setObject:[NSNumber numberWithInt:0] forKey:kW3CMediaFormatWidth];
  458. [formatData setObject:[NSNumber numberWithInt:0] forKey:kW3CMediaFormatDuration];
  459.  
  460. if ([mimeType rangeOfString:@"image/"].location != NSNotFound) {
  461. UIImage* image = [UIImage imageWithContentsOfFile:fullPath];
  462. if (image) {
  463. CGSize imgSize = [image size];
  464. [formatData setObject:[NSNumber numberWithInteger:imgSize.width] forKey:kW3CMediaFormatWidth];
  465. [formatData setObject:[NSNumber numberWithInteger:imgSize.height] forKey:kW3CMediaFormatHeight];
  466. }
  467. } else if (([mimeType rangeOfString:@"video/"].location != NSNotFound) && (NSClassFromString(@"AVURLAsset") != nil)) {
  468. NSURL* movieURL = [NSURL fileURLWithPath:fullPath];
  469. AVURLAsset* movieAsset = [[AVURLAsset alloc] initWithURL:movieURL options:nil];
  470. CMTime duration = [movieAsset duration];
  471. [formatData setObject:[NSNumber numberWithFloat:CMTimeGetSeconds(duration)] forKey:kW3CMediaFormatDuration];
  472.  
  473. NSArray* allVideoTracks = [movieAsset tracksWithMediaType:AVMediaTypeVideo];
  474. if ([allVideoTracks count] > 0) {
  475. AVAssetTrack* track = [[movieAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
  476. CGSize size = [track naturalSize];
  477.  
  478. [formatData setObject:[NSNumber numberWithFloat:size.height] forKey:kW3CMediaFormatHeight];
  479. [formatData setObject:[NSNumber numberWithFloat:size.width] forKey:kW3CMediaFormatWidth];
  480. // not sure how to get codecs or bitrate???
  481. // AVMetadataItem
  482. // AudioFile
  483. } else {
  484. NSLog(@"No video tracks found for %@", fullPath);
  485. }
  486. } else if ([mimeType rangeOfString:@"audio/"].location != NSNotFound) {
  487. if (NSClassFromString(@"AVAudioPlayer") != nil) {
  488. NSURL* fileURL = [NSURL fileURLWithPath:fullPath];
  489. NSError* err = nil;
  490.  
  491. AVAudioPlayer* avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&err];
  492. if (!err) {
  493. // get the data
  494. [formatData setObject:[NSNumber numberWithDouble:[avPlayer duration]] forKey:kW3CMediaFormatDuration];
  495. if ([avPlayer respondsToSelector:@selector(settings)]) {
  496. NSDictionary* info = [avPlayer settings];
  497. NSNumber* bitRate = [info objectForKey:AVEncoderBitRateKey];
  498. if (bitRate) {
  499. [formatData setObject:bitRate forKey:kW3CMediaFormatBitrate];
  500. }
  501. }
  502. } // else leave data init'ed to 0
  503. }
  504. }
  505. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:formatData];
  506. // NSLog(@"getFormatData: %@", [formatData description]);
  507. }
  508. if (bError) {
  509. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:(int)errorCode];
  510. }
  511. if (result) {
  512. [self.commandDelegate sendPluginResult:result callbackId:callbackId];
  513. }
  514. }
  515.  
  516. - (NSDictionary*)getMediaDictionaryFromPath:(NSString*)fullPath ofType:(NSString*)type
  517. {
  518. NSFileManager* fileMgr = [[NSFileManager alloc] init];
  519. NSMutableDictionary* fileDict = [NSMutableDictionary dictionaryWithCapacity:5];
  520.  
  521. CDVFile *fs = [self.commandDelegate getCommandInstance:@"File"];
  522.  
  523. // Get canonical version of localPath
  524. NSURL *fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@", fullPath]];
  525. NSURL *resolvedFileURL = [fileURL URLByResolvingSymlinksInPath];
  526. NSString *path = [resolvedFileURL path];
  527.  
  528. CDVFilesystemURL *url = [fs fileSystemURLforLocalPath:path];
  529.  
  530. [fileDict setObject:[fullPath lastPathComponent] forKey:@"name"];
  531. [fileDict setObject:fullPath forKey:@"fullPath"];
  532. if (url) {
  533. [fileDict setObject:[url absoluteURL] forKey:@"localURL"];
  534. }
  535. // determine type
  536. if (!type) {
  537. id command = [self.commandDelegate getCommandInstance:@"File"];
  538. if ([command isKindOfClass:[CDVFile class]]) {
  539. CDVFile* cdvFile = (CDVFile*)command;
  540. NSString* mimeType = [cdvFile getMimeTypeFromPath:fullPath];
  541. [fileDict setObject:(mimeType != nil ? (NSObject*)mimeType : [NSNull null]) forKey:@"type"];
  542. }
  543. }
  544. NSDictionary* fileAttrs = [fileMgr attributesOfItemAtPath:fullPath error:nil];
  545. [fileDict setObject:[NSNumber numberWithUnsignedLongLong:[fileAttrs fileSize]] forKey:@"size"];
  546. NSDate* modDate = [fileAttrs fileModificationDate];
  547. NSNumber* msDate = [NSNumber numberWithDouble:[modDate timeIntervalSince1970] * 1000];
  548. [fileDict setObject:msDate forKey:@"lastModifiedDate"];
  549.  
  550. return fileDict;
  551. }
  552.  
  553. - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo
  554. {
  555. // older api calls new one
  556. [self imagePickerController:picker didFinishPickingMediaWithInfo:editingInfo];
  557. }
  558.  
  559. /* Called when image/movie is finished recording.
  560. * Calls success or error code as appropriate
  561. * if successful, result contains an array (with just one entry since can only get one image unless build own camera UI) of MediaFile object representing the image
  562. * name
  563. * fullPath
  564. * type
  565. * lastModifiedDate
  566. * size
  567. */
  568. - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
  569. {
  570. CDVImagePicker* cameraPicker = (CDVImagePicker*)picker;
  571. NSString* callbackId = cameraPicker.callbackId;
  572.  
  573. [[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
  574.  
  575. CDVPluginResult* result = nil;
  576.  
  577. UIImage* image = nil;
  578. NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
  579. if (!mediaType || [mediaType isEqualToString:(NSString*)kUTTypeImage]) {
  580. // mediaType is nil then only option is UIImagePickerControllerOriginalImage
  581. if ([UIImagePickerController respondsToSelector:@selector(allowsEditing)] &&
  582. (cameraPicker.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage])) {
  583. image = [info objectForKey:UIImagePickerControllerEditedImage];
  584. } else {
  585. image = [info objectForKey:UIImagePickerControllerOriginalImage];
  586. }
  587. }
  588. if (image != nil) {
  589. // mediaType was image
  590. result = [self processImage:image type:cameraPicker.mimeType forCallbackId:callbackId];
  591. } else if ([mediaType isEqualToString:(NSString*)kUTTypeMovie]) {
  592. // process video
  593. NSString* moviePath = [(NSURL *)[info objectForKey:UIImagePickerControllerMediaURL] path];
  594. if (moviePath) {
  595. result = [self processVideo:moviePath forCallbackId:callbackId];
  596. }
  597. }
  598. if (!result) {
  599. result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_INTERNAL_ERR];
  600. }
  601. [self.commandDelegate sendPluginResult:result callbackId:callbackId];
  602. pickerController = nil;
  603. }
  604.  
  605. - (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
  606. {
  607. CDVImagePicker* cameraPicker = (CDVImagePicker*)picker;
  608. NSString* callbackId = cameraPicker.callbackId;
  609.  
  610. [[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
  611.  
  612. CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NO_MEDIA_FILES];
  613. [self.commandDelegate sendPluginResult:result callbackId:callbackId];
  614. pickerController = nil;
  615. }
  616.  
  617. @end
  618.  
  619. @implementation CDVAudioNavigationController
  620.  
  621. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
  622. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  623. {
  624. // delegate to CVDAudioRecorderViewController
  625. return [self.topViewController supportedInterfaceOrientations];
  626. }
  627. #else
  628. - (NSUInteger)supportedInterfaceOrientations
  629. {
  630. // delegate to CVDAudioRecorderViewController
  631. return [self.topViewController supportedInterfaceOrientations];
  632. }
  633. #endif
  634.  
  635. @end
  636.  
  637. @interface CDVAudioRecorderViewController () {
  638. UIStatusBarStyle _previousStatusBarStyle;
  639. }
  640. @end
  641.  
  642. @implementation CDVAudioRecorderViewController
  643. @synthesize errorCode, callbackId, duration, captureCommand, doneButton, recordingView, recordButton, recordImage, stopRecordImage, timerLabel, avRecorder, avSession, pluginResult, timer, isTimed;
  644.  
  645. - (NSString*)resolveImageResource:(NSString*)resource
  646. {
  647. NSString* systemVersion = [[UIDevice currentDevice] systemVersion];
  648. BOOL isLessThaniOS4 = ([systemVersion compare:@"4.0" options:NSNumericSearch] == NSOrderedAscending);
  649.  
  650. // the iPad image (nor retina) differentiation code was not in 3.x, and we have to explicitly set the path
  651. // if user wants iPhone only app to run on iPad they must remove *~ipad.* images from CDVCapture.bundle
  652. if (isLessThaniOS4) {
  653. NSString* iPadResource = [NSString stringWithFormat:@"%@~ipad.png", resource];
  654. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && [UIImage imageNamed:iPadResource]) {
  655. return iPadResource;
  656. } else {
  657. return [NSString stringWithFormat:@"%@.png", resource];
  658. }
  659. }
  660.  
  661. return resource;
  662. }
  663.  
  664. - (id)initWithCommand:(CDVCapture*)theCommand duration:(NSNumber*)theDuration callbackId:(NSString*)theCallbackId
  665. {
  666. if ((self = [super init])) {
  667. self.captureCommand = theCommand;
  668. self.duration = theDuration;
  669. self.callbackId = theCallbackId;
  670. self.errorCode = CAPTURE_NO_MEDIA_FILES;
  671. self.isTimed = self.duration != nil;
  672. _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
  673.  
  674. return self;
  675. }
  676.  
  677. return nil;
  678. }
  679.  
  680. - (void)loadView
  681. {
  682. if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
  683. self.edgesForExtendedLayout = UIRectEdgeNone;
  684. }
  685.  
  686. // create view and display
  687. CGRect viewRect = [[UIScreen mainScreen] applicationFrame];
  688. UIView* tmp = [[UIView alloc] initWithFrame:viewRect];
  689.  
  690. // make backgrounds
  691. NSString* microphoneResource = @"CDVCapture.bundle/microphone";
  692.  
  693. BOOL isIphone5 = ([[UIScreen mainScreen] bounds].size.width == 568 && [[UIScreen mainScreen] bounds].size.height == 320) || ([[UIScreen mainScreen] bounds].size.height == 568 && [[UIScreen mainScreen] bounds].size.width == 320);
  694. if (isIphone5) {
  695. microphoneResource = @"CDVCapture.bundle/microphone-568h";
  696. }
  697.  
  698. NSBundle* cdvBundle = [NSBundle bundleForClass:[CDVCapture class]];
  699. UIImage* microphone = [UIImage imageNamed:[self resolveImageResource:microphoneResource] inBundle:cdvBundle compatibleWithTraitCollection:nil];
  700. UIView* microphoneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewRect.size.width, microphone.size.height)];
  701. [microphoneView setBackgroundColor:[UIColor colorWithPatternImage:microphone]];
  702. [microphoneView setUserInteractionEnabled:NO];
  703. [microphoneView setIsAccessibilityElement:NO];
  704. [tmp addSubview:microphoneView];
  705.  
  706. // add bottom bar view
  707. UIImage* grayBkg = [UIImage imageNamed:[self resolveImageResource:@"CDVCapture.bundle/controls_bg"] inBundle:cdvBundle compatibleWithTraitCollection:nil];
  708. UIView* controls = [[UIView alloc] initWithFrame:CGRectMake(0, microphone.size.height, viewRect.size.width, grayBkg.size.height)];
  709. [controls setBackgroundColor:[UIColor colorWithPatternImage:grayBkg]];
  710. [controls setUserInteractionEnabled:NO];
  711. [controls setIsAccessibilityElement:NO];
  712. [tmp addSubview:controls];
  713.  
  714. // make red recording background view
  715. UIImage* recordingBkg = [UIImage imageNamed:[self resolveImageResource:@"CDVCapture.bundle/recording_bg"] inBundle:cdvBundle compatibleWithTraitCollection:nil];
  716. UIColor* background = [UIColor colorWithPatternImage:recordingBkg];
  717. self.recordingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewRect.size.width, recordingBkg.size.height)];
  718. [self.recordingView setBackgroundColor:background];
  719. [self.recordingView setHidden:YES];
  720. [self.recordingView setUserInteractionEnabled:NO];
  721. [self.recordingView setIsAccessibilityElement:NO];
  722. [tmp addSubview:self.recordingView];
  723.  
  724. // add label
  725. self.timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewRect.size.width, recordingBkg.size.height)];
  726. // timerLabel.autoresizingMask = reSizeMask;
  727. [self.timerLabel setBackgroundColor:[UIColor clearColor]];
  728. [self.timerLabel setTextColor:[UIColor whiteColor]];
  729. #ifdef __IPHONE_6_0
  730. [self.timerLabel setTextAlignment:NSTextAlignmentCenter];
  731. #else
  732. // for iOS SDK < 6.0
  733. [self.timerLabel setTextAlignment:UITextAlignmentCenter];
  734. #endif
  735. [self.timerLabel setText:@"0:00"];
  736. [self.timerLabel setAccessibilityHint:PluginLocalizedString(captureCommand, @"recorded time in minutes and seconds", nil)];
  737. self.timerLabel.accessibilityTraits |= UIAccessibilityTraitUpdatesFrequently;
  738. self.timerLabel.accessibilityTraits &= ~UIAccessibilityTraitStaticText;
  739. [tmp addSubview:self.timerLabel];
  740.  
  741. // Add record button
  742.  
  743. self.recordImage = [UIImage imageNamed:[self resolveImageResource:@"CDVCapture.bundle/record_button"] inBundle:cdvBundle compatibleWithTraitCollection:nil];
  744. self.stopRecordImage = [UIImage imageNamed:[self resolveImageResource:@"CDVCapture.bundle/stop_button"] inBundle:cdvBundle compatibleWithTraitCollection:nil];
  745. self.recordButton.accessibilityTraits |= [self accessibilityTraits];
  746. self.recordButton = [[UIButton alloc] initWithFrame:CGRectMake((viewRect.size.width - recordImage.size.width) / 2, (microphone.size.height + (grayBkg.size.height - recordImage.size.height) / 2), recordImage.size.width, recordImage.size.height)];
  747. [self.recordButton setAccessibilityLabel:PluginLocalizedString(captureCommand, @"toggle audio recording", nil)];
  748. [self.recordButton setImage:recordImage forState:UIControlStateNormal];
  749. [self.recordButton addTarget:self action:@selector(processButton:) forControlEvents:UIControlEventTouchUpInside];
  750. [tmp addSubview:recordButton];
  751.  
  752. // make and add done button to navigation bar
  753. self.doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissAudioView:)];
  754. [self.doneButton setStyle:UIBarButtonItemStyleDone];
  755. self.navigationItem.rightBarButtonItem = self.doneButton;
  756.  
  757. [self setView:tmp];
  758. }
  759.  
  760. - (void)viewDidLoad
  761. {
  762. [super viewDidLoad];
  763. UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
  764. NSError* error = nil;
  765.  
  766. if (self.avSession == nil) {
  767. // create audio session
  768. self.avSession = [AVAudioSession sharedInstance];
  769. if (error) {
  770. // return error if can't create recording audio session
  771. NSLog(@"error creating audio session: %@", [[error userInfo] description]);
  772. self.errorCode = CAPTURE_INTERNAL_ERR;
  773. [self dismissAudioView:nil];
  774. }
  775. }
  776.  
  777. // create file to record to in temporary dir
  778.  
  779. NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath]; // use file system temporary directory
  780. NSError* err = nil;
  781. NSFileManager* fileMgr = [[NSFileManager alloc] init];
  782.  
  783. // generate unique file name
  784. NSString* filePath;
  785. int i = 1;
  786. do {
  787. filePath = [NSString stringWithFormat:@"%@/audio_%03d.wav", docsPath, i++];
  788. } while ([fileMgr fileExistsAtPath:filePath]);
  789.  
  790. NSURL* fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
  791.  
  792. // create AVAudioPlayer
  793. NSDictionary *recordSetting = [[NSMutableDictionary alloc] init];
  794. self.avRecorder = [[AVAudioRecorder alloc] initWithURL:fileURL settings:recordSetting error:&err];
  795. if (err) {
  796. NSLog(@"Failed to initialize AVAudioRecorder: %@\n", [err localizedDescription]);
  797. self.avRecorder = nil;
  798. // return error
  799. self.errorCode = CAPTURE_INTERNAL_ERR;
  800. [self dismissAudioView:nil];
  801. } else {
  802. self.avRecorder.delegate = self;
  803. [self.avRecorder prepareToRecord];
  804. self.recordButton.enabled = YES;
  805. self.doneButton.enabled = YES;
  806. }
  807. }
  808.  
  809. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
  810. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  811. {
  812. UIInterfaceOrientationMask orientation = UIInterfaceOrientationMaskPortrait;
  813. UIInterfaceOrientationMask supported = [captureCommand.viewController supportedInterfaceOrientations];
  814.  
  815. orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown);
  816. return orientation;
  817. }
  818. #else
  819. - (NSUInteger)supportedInterfaceOrientations
  820. {
  821. NSUInteger orientation = UIInterfaceOrientationMaskPortrait; // must support portrait
  822. NSUInteger supported = [captureCommand.viewController supportedInterfaceOrientations];
  823.  
  824. orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown);
  825. return orientation;
  826. }
  827. #endif
  828.  
  829. - (void)viewDidUnload
  830. {
  831. [self setView:nil];
  832. [self.captureCommand setInUse:NO];
  833. }
  834.  
  835. - (void)processButton:(id)sender
  836. {
  837. if (self.avRecorder.recording) {
  838. // stop recording
  839. [self.avRecorder stop];
  840. self.isTimed = NO; // recording was stopped via button so reset isTimed
  841. // view cleanup will occur in audioRecordingDidFinishRecording
  842. } else {
  843. // begin recording
  844. [self.recordButton setImage:stopRecordImage forState:UIControlStateNormal];
  845. self.recordButton.accessibilityTraits &= ~[self accessibilityTraits];
  846. [self.recordingView setHidden:NO];
  847. __block NSError* error = nil;
  848.  
  849. __weak CDVAudioRecorderViewController* weakSelf = self;
  850.  
  851. void (^startRecording)(void) = ^{
  852. [weakSelf.avSession setCategory:AVAudioSessionCategoryRecord error:&error];
  853. [weakSelf.avSession setActive:YES error:&error];
  854. if (error) {
  855. // can't continue without active audio session
  856. weakSelf.errorCode = CAPTURE_INTERNAL_ERR;
  857. [weakSelf dismissAudioView:nil];
  858. } else {
  859. if (weakSelf.duration) {
  860. weakSelf.isTimed = true;
  861. [weakSelf.avRecorder recordForDuration:[duration doubleValue]];
  862. } else {
  863. [weakSelf.avRecorder record];
  864. }
  865. [weakSelf.timerLabel setText:@"0.00"];
  866. weakSelf.timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:weakSelf selector:@selector(updateTime) userInfo:nil repeats:YES];
  867. weakSelf.doneButton.enabled = NO;
  868. }
  869. UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
  870. };
  871.  
  872. SEL rrpSel = NSSelectorFromString(@"requestRecordPermission:");
  873. if ([self.avSession respondsToSelector:rrpSel])
  874. {
  875. #pragma clang diagnostic push
  876. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  877. [self.avSession performSelector:rrpSel withObject:^(BOOL granted){
  878. if (granted) {
  879. startRecording();
  880. } else {
  881. NSLog(@"Error creating audio session, microphone permission denied.");
  882. weakSelf.errorCode = CAPTURE_INTERNAL_ERR;
  883. [weakSelf dismissAudioView:nil];
  884. }
  885. }];
  886. #pragma clang diagnostic pop
  887. } else {
  888. startRecording();
  889. }
  890. }
  891. }
  892.  
  893. /*
  894. * helper method to clean up when stop recording
  895. */
  896. - (void)stopRecordingCleanup
  897. {
  898. if (self.avRecorder.recording) {
  899. [self.avRecorder stop];
  900. }
  901. [self.recordButton setImage:recordImage forState:UIControlStateNormal];
  902. self.recordButton.accessibilityTraits |= [self accessibilityTraits];
  903. [self.recordingView setHidden:YES];
  904. self.doneButton.enabled = YES;
  905. if (self.avSession) {
  906. // deactivate session so sounds can come through
  907. [self.avSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
  908. [self.avSession setActive:NO error:nil];
  909. }
  910. if (self.duration && self.isTimed) {
  911. // VoiceOver announcement so user knows timed recording has finished
  912. //BOOL isUIAccessibilityAnnouncementNotification = (&UIAccessibilityAnnouncementNotification != NULL);
  913. if (UIAccessibilityAnnouncementNotification) {
  914. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 500ull * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
  915. UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, PluginLocalizedString(captureCommand, @"timed recording complete", nil));
  916. });
  917. }
  918. } else {
  919. // issue a layout notification change so that VO will reannounce the button label when recording completes
  920. UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
  921. }
  922. }
  923.  
  924. - (void)dismissAudioView:(id)sender
  925. {
  926. // called when done button pressed or when error condition to do cleanup and remove view
  927. [[self.captureCommand.viewController.presentedViewController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
  928.  
  929. if (!self.pluginResult) {
  930. // return error
  931. self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:(int)self.errorCode];
  932. }
  933.  
  934. self.avRecorder = nil;
  935. [self.avSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
  936. [self.avSession setActive:NO error:nil];
  937. [self.captureCommand setInUse:NO];
  938. UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
  939. // return result
  940. [self.captureCommand.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
  941.  
  942. if (IsAtLeastiOSVersion(@"7.0")) {
  943. [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle];
  944. }
  945. }
  946.  
  947. - (void)updateTime
  948. {
  949. // update the label with the elapsed time
  950. [self.timerLabel setText:[self formatTime:self.avRecorder.currentTime]];
  951. }
  952.  
  953. - (NSString*)formatTime:(int)interval
  954. {
  955. // is this format universal?
  956. int secs = interval % 60;
  957. int min = interval / 60;
  958.  
  959. if (interval < 60) {
  960. return [NSString stringWithFormat:@"0:%02d", interval];
  961. } else {
  962. return [NSString stringWithFormat:@"%d:%02d", min, secs];
  963. }
  964. }
  965.  
  966. - (void)audioRecorderDidFinishRecording:(AVAudioRecorder*)recorder successfully:(BOOL)flag
  967. {
  968. // may be called when timed audio finishes - need to stop time and reset buttons
  969. [self.timer invalidate];
  970. [self stopRecordingCleanup];
  971.  
  972. // generate success result
  973. if (flag) {
  974. NSString* filePath = [avRecorder.url path];
  975. // NSLog(@"filePath: %@", filePath);
  976. NSDictionary* fileDict = [captureCommand getMediaDictionaryFromPath:filePath ofType:@"audio/wav"];
  977. NSArray* fileArray = [NSArray arrayWithObject:fileDict];
  978.  
  979. self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:fileArray];
  980. } else {
  981. self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageToErrorObject:CAPTURE_INTERNAL_ERR];
  982. }
  983. }
  984.  
  985. - (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder*)recorder error:(NSError*)error
  986. {
  987. [self.timer invalidate];
  988. [self stopRecordingCleanup];
  989.  
  990. NSLog(@"error recording audio");
  991. self.pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageToErrorObject:CAPTURE_INTERNAL_ERR];
  992. [self dismissAudioView:nil];
  993. }
  994.  
  995. - (UIStatusBarStyle)preferredStatusBarStyle
  996. {
  997. return UIStatusBarStyleDefault;
  998. }
  999.  
  1000. - (void)viewWillAppear:(BOOL)animated
  1001. {
  1002. if (IsAtLeastiOSVersion(@"7.0")) {
  1003. [[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
  1004. }
  1005.  
  1006. [super viewWillAppear:animated];
  1007. }
  1008.  
  1009. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement