2017-11-09 15 views

答えて

1

使用これを、iOSの9から

func flashlight() { 
    let flashLight: AVCaptureDevice? = AVCaptureDevice.default(for: .video) 
    if flashLight?.isTorchAvailable() && flashLight?.isTorchModeSupported(.on) { 
     let success: Bool? = try? flashLight?.lockForConfiguration() 
     if success ?? false { 
      if flashLight?.isTorchActive() != nil { 
       flashLight?.torchMode = .off 
      } 
      else { 
       flashLight?.torchMode = .on 
      } 
      flashLight?.unlockForConfiguration() 
     } 
    } 
} 

は、画面の記録がReplayKitようになりますが大幅にこれを簡素化することが可能です。より多くの情報をご覧ください

func startRecording(_ sender: UIBarButtonItem, _ r: RPScreenRecorder) { 

    r.startRecording(handler: { (error: Error?) -> Void in 
     if error == nil { // Recording has started 
      sender.title = "Stop" 
     } else { 
      // Handle error 
      print(error?.localizedDescription ?? "Unknown error") 
     } 
    }) 
} 

func stopRecording(_ sender: UIBarButtonItem, _ r: RPScreenRecorder) { 
    r.stopRecording(handler: { previewViewController, error in 

     sender.title = "Record" 

     if let pvc = previewViewController { 

      if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad { 
       pvc.modalPresentationStyle = UIModalPresentationStyle.popover 
       pvc.popoverPresentationController?.sourceRect = CGRect.zero 
       pvc.popoverPresentationController?.sourceView = self.view 
      } 

      pvc.previewControllerDelegate = self 
      self.present(pvc, animated: true, completion: nil) 
     } 
     else if let error = error { 
      print(error.localizedDescription) 
     } 

    }) 
} 

// MARK: RPPreviewViewControllerDelegate 
func previewControllerDidFinish(_ previewController: RPPreviewViewController) { 
    previewController.dismiss(animated: true, completion: nil) 
} 

このリンク:https://developer.apple.com/reference/replaykit

関連する問題