khenid

Untitled

Mar 11th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UIKit
  2. import StoreKit
  3.  
  4. class QRCodeGenerator: UIViewController {
  5.  
  6.     var product_id: NSString?;
  7.     @IBOutlet weak var userText: UITextView!
  8.     @IBOutlet weak var infoLabel: UILabel!
  9.     var qrString : String?
  10.     var segue = true
  11.     var codeCount = 0
  12.     override func viewDidLoad() {
  13.        
  14.         product_id = "FullAccess"
  15.         super.viewDidLoad()
  16.         self.navigationItem.title = "QR Code Generator"
  17.         self.userText.text = self.qrString
  18.     }
  19.    
  20.     override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
  21.        
  22.         if segue!.identifier == "QR" {
  23.             if self.userText.text != ""{
  24.                 let ImageviewController : QRImage = segue!.destinationViewController as QRImage
  25.                 ImageviewController.userTextString = self.userText.text
  26.             }
  27.         }
  28.     }
  29.  
  30.     override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
  31.        
  32.         if identifier == "QR"{
  33.            
  34.             if (userText.text.isEmpty) {
  35.                
  36.                 let alert = UIAlertView()
  37.                 alert.title = "No Text"
  38.                 alert.message = "Please Enter Text In The Box"
  39.                 alert.addButtonWithTitle("Ok")
  40.                 alert.show()
  41.                
  42.                 return false
  43.             }
  44.             else {
  45.                 return true
  46.             }
  47.         }
  48.        
  49.         // by default, transition
  50.         return true
  51.     }
  52.    
  53.     override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  54.        
  55.         self.view.endEditing(true)
  56.     }
  57.     @IBAction func showMeQRCodeAction(sender: AnyObject) {
  58.        
  59.             if self.segue{
  60.                
  61.                 let fileManger = NSFileManager.defaultManager()
  62.                 var error : NSError?
  63.                 var doumentDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
  64.                 let destinationPath = doumentDirectoryPath.stringByAppendingPathComponent("QRGenerator.plist")
  65.                 var data : NSMutableDictionary?
  66.                 data = NSMutableDictionary(contentsOfFile: destinationPath)
  67.                 var QRCount : Int = data?.objectForKey("QRCount") as Int
  68.                 QRCount++
  69.                 self.codeCount = QRCount
  70.                 if QRCount > 10{
  71.        
  72.                     println("Called")
  73.                    
  74.                 }
  75.                 data?.setObject(QRCount, forKey: "QRCount")
  76.                 data?.writeToFile(destinationPath, atomically: true)
  77.                 println(data!)
  78.                
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment