@IBAction func changeButton(_ sender: Any) {
DispatchQueue.global().async {
DispatchQueue.main.async(){
self.table.isHidden = true
self.activityIndicator.startAnimating()
}
/*Внутри функций работа с сетью, sqlite базой, много циклов*/
self.func1()
self.func2()
DispatchQueue.main.async(){
self.readLovers() - тут подгрузка данных для table, соот., и table.reloadData()
self.activityIndicator.stopAnimating()
self.table.isHidden = false
}
}
}
import UIKit
import MediaPlayer
import AVFoundation
class testVC: UIViewController, {
private var audioLevel : Float = 0.0
@IBOutlet weak var label1: UILabel!
var imagePicker: UIImagePickerController!
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
listenVolumeButton()
}
func listenVolumeButton(){
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setActive(true, options: [])
audioSession.addObserver(self, forKeyPath: "outputVolume",
options: NSKeyValueObservingOptions.new, context: nil)
audioLevel = audioSession.outputVolume
} catch {
print("Error")
}
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "outputVolume"{
print("GoodBye")
let audioSession = AVAudioSession.sharedInstance()
if audioSession.outputVolume > audioLevel {
print("Hello")
audioLevel = audioSession.outputVolume
}
if audioSession.outputVolume < audioLevel {
print("GoodBye")
audioLevel = audioSession.outputVolume
}
if audioSession.outputVolume > 0.999 {
(MPVolumeView().subviews.filter{NSStringFromClass($0.classForCoder) == "MPVolumeSlider"}.first as? UISlider)?.setValue(0.9375, animated: false)
audioLevel = 0.9375
}
if audioSession.outputVolume < 0.001 {
(MPVolumeView().subviews.filter{NSStringFromClass($0.classForCoder) == "MPVolumeSlider"}.first as? UISlider)?.setValue(0.0625, animated: false)
audioLevel = 0.0625
}
}
}
}
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(KeyBoard), name: UIResponder.keyboardDidHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyBoard), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
@objc func KeyBoard(notification: Notification){
let userInfo = notification.userInfo!
let keyBoardScreenEndFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
let keyBoardViewEndFrame = view.convert(keyBoardScreenEndFrame, from: view.window)
if notification.name == UIResponder.keyboardDidHideNotification{
scrollView.contentInset = UIEdgeInsets.zero
}
if notification.name == UIResponder.keyboardWillChangeFrameNotification{
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyBoardViewEndFrame.height, right: 0)
}
scrollView.scrollIndicatorInsets = scrollView.contentInset
}
view.endEditing(true)
let receiptUrl: URL = Bundle.main.appStoreReceiptURL!
var receipt: Data?
receipt = try! NSData.init(contentsOf: receiptUrl) as Data
print(receipt)
var base64encodedReceipt: String = receipt!.base64EncodedString()
base64encodedReceipt = base64encodedReceipt.replacingOccurrences(of: "+", with: "%2B")
let vkUrl = URL(string: "test.php")
var request = URLRequest(url: vkUrl!)
let postString: String = "receipt-data=" + base64encodedReceipt
request.httpBody = postString.data(using: String.Encoding.utf8);
request.httpMethod = "POST"
request.addValue("\(postString.count)", forHTTPHeaderField: "Content-Length")
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-type")
URLSession.shared.dataTask(with: request) {(data, response, error) in
guard let data = data else {
let error_code = String(error!._code)
let error_description = String(error!.localizedDescription)
let error_msg = "Ошибка соединения. Пожалуйста, попробуйте позже. \n Если ошибка будет повторяться, то сообщите в службу поддержки приложения. \n Код ошибки: " + error_code + " \n Описание ошибки: \n" + error_description
let alertVC = UIAlertController(title: "Ошибка", message: error_msg, preferredStyle: .alert)
let actionOK = UIAlertAction(title: "OK", style: .default)
alertVC.addAction(actionOK)
DispatchQueue.main.async(execute: {
self.present(alertVC, animated: true, completion: nil)
})
return
}
do {
json = data
k = true
}
}.resume()
<?php
$json['receipt-data'] = $_POST['receipt-data'];
$post = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://buy.itunes.apple.com/verifyReceipt");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>