<commit_before>//
//  IGRPhotoTweakViewController+PHPhotoLibrary.swift
//  Pods
//
//  Created by <NAME> on 4/26/17.
//
//

import Foundation
import Photos

extension IGRPhotoTweakViewController {
    
    internal func saveToLibrary(image: UIImage) {
        let writePhotoToLibraryBlock: (() -> Void)? = {
            UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(image:didFinishSavingWithError:contextInfo:)), nil)
        }
        
        if PHPhotoLibrary.authorizationStatus() == PHAuthorizationStatus.authorized {
            writePhotoToLibraryBlock!()
        }
        else {
            PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) in
                if status == PHAuthorizationStatus.authorized {
                    DispatchQueue.main.async{
                        writePhotoToLibraryBlock!()
                    }
                }
                else {
                    DispatchQueue.main.async{
                        let ac = UIAlertController(title: "Authorization error",
                                                   message: "App don't granted to access to Photo Library",
                                                   preferredStyle: .alert)
                        ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                        ac.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
                            guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
                                return
                            }
                            
                            if UIApplication.shared.canOpenURL(settingsUrl) {
                                if #available(iOS 10.0, *) {
                                    UIApplication.shared.open(settingsUrl)
                                } else {
                                    UIApplication.shared.openURL(settingsUrl)
                                }
                            }
                        }))
                        self.present(ac, animated: true, completion: nil)
                    }
                }
            })
        }
    }
    
    @objc func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafeRawPointer) {
        if error == nil {
            let ac = UIAlertController(title: "Save error",
                                       message: error?.localizedDescription,
                                       preferredStyle: .alert)
            ac.addAction(UIAlertAction(title: "OK",
                                       style: .default,
                                       handler: nil))
            present(ac, animated: true, completion: nil)
        }
    }
}<commit_msg>fix issue where error would not be triggered<commit_after>//
//  IGRPhotoTweakViewController+PHPhotoLibrary.swift
//  Pods
//
//  Created by <NAME> on 4/26/17.
//
//

import Foundation
import Photos

extension IGRPhotoTweakViewController {
    
    internal func saveToLibrary(image: UIImage) {
        let writePhotoToLibraryBlock: (() -> Void)? = {
            UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(image:didFinishSavingWithError:contextInfo:)), nil)
        }
        
        if PHPhotoLibrary.authorizationStatus() == PHAuthorizationStatus.authorized {
            writePhotoToLibraryBlock!()
        }
        else {
            PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) in
                if status == PHAuthorizationStatus.authorized {
                    DispatchQueue.main.async{
                        writePhotoToLibraryBlock!()
                    }
                }
                else {
                    DispatchQueue.main.async{
                        let ac = UIAlertController(title: "Authorization error",
                                                   message: "App don't granted to access to Photo Library",
                                                   preferredStyle: .alert)
                        ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                        ac.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
                            guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
                                return
                            }
                            
                            if UIApplication.shared.canOpenURL(settingsUrl) {
                                if #available(iOS 10.0, *) {
                                    UIApplication.shared.open(settingsUrl)
                                } else {
                                    UIApplication.shared.openURL(settingsUrl)
                                }
                            }
                        }))
                        self.present(ac, animated: true, completion: nil)
                    }
                }
            })
        }
    }
    
    @objc func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafeRawPointer) {
        if error != nil {
            let ac = UIAlertController(title: "Save error",
                                       message: error?.localizedDescription,
                                       preferredStyle: .alert)
            ac.addAction(UIAlertAction(title: "OK",
                                       style: .default,
                                       handler: nil))
            present(ac, animated: true, completion: nil)
        }
    }
}
{'fraction_non_alphanumeric': 0.07958784864096642, 'fraction_numerical': 0.0028424231657488007, 'mean_word_length': 1.1787925696594428, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559990', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1216, 'n_words': 249}