1

Is it possible to programmatically take screenshots from within a keyboard app or an iMessage app? If so, how?

Edit: to clarify, I would like to take screenshots of the entire screen (i.e. the currently open app) from within the keyboard/iMessage app.

Richard
  • 639
  • 2
  • 8
  • 24

2 Answers2

5

Since this action would be devastating for privacy of customers who use third-party keyboards or iMessage apps, it is not possible to collect screenshots of personal data in this manner, for obvious reasons.

The question specifically asks for a method to perform a potentially scammy action that is against App Store Review Guidelines, Section 5.1.1 Data Collection and Storage:

(iii) Developers that use their apps to surreptitiously discover passwords or other private data will be removed from the Developer Program.

This question has been flagged accordingly.

Tzar
  • 5,132
  • 4
  • 23
  • 57
  • To clarify, I envisioned this happening only at the request of the user via e.g. tapping a button on a keyboard. – Richard Apr 19 '17 at 19:21
  • Users can already take screenshots via hardware button combinations if they need to. – Tzar Apr 19 '17 at 19:44
  • Right, but it's cumbersome to repeatedly scroll and take a screenshot if the user wants to capture more than what can fit on the screen at a time. I'd like to implement functionality such that the user can press a single button, and screenshots or the entire scrollable area are automatically taken and stitched together. – Richard Apr 19 '17 at 21:34
  • This is different from what you originally asked. It might be possible. Post a new, rephrased question about it, and I’ll try answering. – Tzar Apr 19 '17 at 22:15
  • Thank you @boletzar, I've posted a new question at http://stackoverflow.com/questions/43615790/take-screenshots-programmatically-of-entire-scrollable-area-in-ios – Richard Apr 25 '17 at 16:08
-1

Use this code for taking a screenshot using UIToolBar

extension UIViewController: UITextFieldDelegate{
    func addToolBar(textField: UITextField){
        var toolBar = UIToolbar()
        toolBar.barStyle = UIBarStyle.Default
        toolBar.translucent = true
        toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
        var screenshotButton = UIBarButtonItem(title: "Screenshot", style: UIBarButtonItemStyle.Done, target: self, action: "donePressed")
        var cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "cancelPressed")
        var spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
        toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
        toolBar.userInteractionEnabled = true
        toolBar.sizeToFit()

        textField.delegate = self
        textField.inputAccessoryView = toolBar
    }
    func screenshotButton(){
            func captureScreen() -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
        view.layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    }
    func cancelPressed(){
        view.endEditing(true) // or do something
    }
}

Though I still need to call the code below on all of my text fields.

override func viewDidLoad() {
    super.viewDidLoad()
    addToolBar(addressField)
}
Satish Babariya
  • 3,062
  • 1
  • 15
  • 29
  • Can you clarify? What is a UIToolbar? Will this take a screenshot of the entire screen from within a keyboard or iMessage app? – Richard Apr 10 '17 at 18:13
  • use this for reference on toolbar https://developer.apple.com/reference/uikit/uitoolbar – Satish Babariya Apr 10 '17 at 18:17
  • Thank you for the link. I'm still unsure about whether this addresses my problem, however. Is the UIToolbar a component that can be added into an iMessage app or a keyboard app? If so, does the code you posted take a screenshot of the entire screen, or just of the iMessage/keyboard app? – Richard Apr 10 '17 at 18:20
  • This is for taking screenshots inside the app but the question is different. – Satheesh Apr 17 '17 at 11:41