Skip to content
Snippets Groups Projects
Commit 74205b29 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add method to take a screenshot

parent a800ea9e
Branches
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@
F673A9982635EF510017AD37 /* ResponseHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F673A9922635EF510017AD37 /* ResponseHandler.swift */; };
F673A9992635EF510017AD37 /* RequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F673A9932635EF510017AD37 /* RequestBuilder.swift */; };
F673A9A12635EF8D0017AD37 /* Future in Frameworks */ = {isa = PBXBuildFile; productRef = F673A9A02635EF8D0017AD37 /* Future */; };
F68BFE6B263B28B000E893E5 /* UIViewController+Screenshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68BFE6A263B28B000E893E5 /* UIViewController+Screenshot.swift */; };
F68C2D422616482A00042967 /* IsoDateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F68C2D412616482A00042967 /* IsoDateFormatter.swift */; };
F6A251A0260B670000132DEC /* AppleLibs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A25196260B66FF00132DEC /* AppleLibs.framework */; };
F6A251A5260B670000132DEC /* AppleLibsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6A251A4260B670000132DEC /* AppleLibsTests.swift */; };
......@@ -55,6 +56,7 @@
F673A9912635EF510017AD37 /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
F673A9922635EF510017AD37 /* ResponseHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResponseHandler.swift; sourceTree = "<group>"; };
F673A9932635EF510017AD37 /* RequestBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestBuilder.swift; sourceTree = "<group>"; };
F68BFE6A263B28B000E893E5 /* UIViewController+Screenshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Screenshot.swift"; sourceTree = "<group>"; };
F68C2D412616482A00042967 /* IsoDateFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsoDateFormatter.swift; sourceTree = "<group>"; };
F6A25196260B66FF00132DEC /* AppleLibs.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AppleLibs.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F6A25199260B66FF00132DEC /* AppleLibs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleLibs.h; sourceTree = "<group>"; };
......@@ -140,6 +142,14 @@
path = Requests;
sourceTree = "<group>";
};
F68BFE69263B28A400E893E5 /* View */ = {
isa = PBXGroup;
children = (
F68BFE6A263B28B000E893E5 /* UIViewController+Screenshot.swift */,
);
path = View;
sourceTree = "<group>";
};
F68C2D402616482000042967 /* Date */ = {
isa = PBXGroup;
children = (
......@@ -171,6 +181,7 @@
F6A25198260B66FF00132DEC /* AppleLibs */ = {
isa = PBXGroup;
children = (
F68BFE69263B28A400E893E5 /* View */,
F623A65C2635B36900F50371 /* Network */,
F623A6822635B78500F50371 /* Utils */,
F6A25199260B66FF00132DEC /* AppleLibs.h */,
......@@ -312,6 +323,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F68BFE6B263B28B000E893E5 /* UIViewController+Screenshot.swift in Sources */,
F623A65E2635B38200F50371 /* CharacterSet+Url.swift in Sources */,
F673A9942635EF510017AD37 /* DataManager.swift in Sources */,
F6A251BA260B697300132DEC /* Double+Rounded.swift in Sources */,
......
//
// UIViewController+Screenshot.swift
// AppleLibs
//
// Created by Tobias on 29.04.21.
//
import UIKit
extension UIViewController
{
open func takeScreenshot(_ shouldSave: Bool = true) -> UIImage? {
var screenshotImage :UIImage?
let scale = UIScreen.main.scale
guard let layer = self.view.window?.layer else {
return nil
}
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
layer.render(in:context)
screenshotImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
if let image = screenshotImage, shouldSave {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
return screenshotImage
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment