0

I'm creating an iOS app on Swift 3 and its purpose is to be a browser for a web app already created by me.

I need to create a feature which allow the user to take a picture when he clicks on an input=file in the webview. When he clicks, a nativ menu display :

  • take a photo
  • chose from library
  • chose from cloud

Just for "take a photo", I want to set the rotation of my new taken photo with the actual EXIF Data and save this photo in the library.

I know by default, iOS have a feature which opens a menu when an input=file is clicked, but it doesn't store my picture and I can't set the orientation.

Thanks by advance for your help !

My input on my web app

<input id="input-photo" type="file" name="..." accept="image/*" />

My actual code for my webview

import UIKit

class ViewController: UIViewController, UIWebViewDelegate, UINavigationControllerDelegate {

    var boxView = UIView()

    @IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation");

        let url = URL(string: "https://dispatch-test.reolin.net");
        let request = URLRequest(url: url!);

        webView.delegate = self;
        webView.frame = self.view.bounds;
        webView.scalesPageToFit = true;
        webView.loadRequest(request);
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override var shouldAutorotate: Bool {
        return false;
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait;
    }

    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return .portrait;
    }

    func webViewDidStartLoad(_ webView: UIWebView) {
        // Box config:
        boxView = UIView(frame: CGRect(x: (webView.frame.size.width / 2) - 50, y: (webView.frame.size.height / 2) - 50, width: 100, height: 100))
        boxView.backgroundColor = UIColor.black
        boxView.alpha = 0.9
        boxView.layer.cornerRadius = 10

        // Spin config:
        let activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
        activityView.frame = CGRect(x: 23, y: 16, width: 53, height: 53)
        activityView.startAnimating()

        // Text config:
        let textLabel = UILabel(frame: CGRect(x: 0, y: 70, width: 100, height: 30))
        textLabel.textColor = UIColor.white
        textLabel.textAlignment = .center
        textLabel.font = UIFont(name: textLabel.font.fontName, size: 13)
        textLabel.text = "Chargement"

        // Activate:
        boxView.addSubview(activityView)
        boxView.addSubview(textLabel)
        webView.addSubview(boxView)
    }

    func webViewDidFinishLoad(_ webView: UIWebView) {
        // Removes it:
        boxView.removeFromSuperview()
    }
}
Maitre Manuel
  • 21
  • 1
  • 5
  • check this how javascript can initiate call to your controller https://stackoverflow.com/a/37358818/6132334 – xmhafiz Jun 06 '17 at 16:18
  • I don't want Javascript call my controller. When I created the same app on Android, I didn't need to do that. I just want to catch the moment when the phone creates the photo and manipulate the photo before iOS upload it to my webview. – Maitre Manuel Jun 07 '17 at 09:16

0 Answers0