swift: UIDocumentPickerViewController-plugin com.apple.UIKit.fileprovider.default invalidated - ios

I have a problem regarding the plugin configuration.I searched but found no answers anywhere. Here is my code
import UIKit
import MobileCoreServices
class ViewController: UIViewController, UIDocumentPickerDelegate,UITextViewDelegate {
#IBOutlet weak var webView: UIWebView!
#IBOutlet weak var emailButton: UIButton!
#IBOutlet weak var UITextField: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func handleImportPickerPressed(sender: AnyObject) {
let documentPicker = UIDocumentPickerViewController(documentTypes:["public.data", "public.text"],inMode: UIDocumentPickerMode.Import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = UIModalPresentationStyle.FormSheet
presentViewController(documentPicker, animated: true, completion: nil)
}
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {
print(url)
if controller.documentPickerMode == UIDocumentPickerMode.Open{
print("this is a Open")
}
if controller.documentPickerMode == UIDocumentPickerMode.Import{
print("this is a Import")
}
if controller.documentPickerMode == UIDocumentPickerMode.ExportToService{
print("this is a ExportToService")
}
if controller.documentPickerMode == UIDocumentPickerMode.MoveToService{
print("this is a MoveToService")
}
}
}
and also the output in the console is
this is a Import
2017-01-18 10:29:22.968 IBooksTest[442:43393] plugin com.apple.UIKit.fileprovider.default invalidated
what is wrong here or am i going in wrong direction?. i even looked at similar problem Here but still issue is same.
Thanks,

Related

swift: iClouds Documents seems to be disabled when loaded from custom application

i am trying to upload the PDF files from iCloud in my custom application. But as i move to iCloud from my application the documents cannot be selected it seems like as if they are disabled. Most of all the explanations are in Obj-C so i could no understand exactly.
What is wrong here? This is my code in swift2:
import UIKit
import MobileCoreServices
class ViewController: UIViewController, UIDocumentPickerDelegate, UITextViewDelegate {
#IBOutlet weak var emailButton: UIButton!
#IBOutlet weak var UITextField: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func handleImportPickerPressed(sender: AnyObject) {
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeText as NSString as String], inMode: .Import)
documentPicker.delegate = self
presentViewController(documentPicker, animated: true, completion: nil)
}
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {
print(url)
}
They are disable means that document types you have in your iCloud does not match while your are selecting.Use documents types as:
#IBAction func handleImportPickerPressed(sender: AnyObject) {
let documentPicker = UIDocumentPickerViewController(documentTypes:["public.data", "public.text"],inMode: UIDocumentPickerMode.Import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = UIModalPresentationStyle.FormSheet
presentViewController(documentPicker, animated: true, completion: nil)
}
There are many other document types. They are disable means that they cannot be read by the documentTypes you are passing.

Upload Image to Dropbox using SwiftyDropbox

I am trying to upload an image in a UIImageView to Dropbox using SwiftyDropbox and Swift 3.0. When I press the button nothing happens after the first print statement. What am I doing wrong.
import UIKit
import SwiftyDropbox
class ViewController: UIViewController {
let client = DropboxClientsManager.authorizedClient
#IBOutlet weak var myPhotoView: UIImageView!
#IBAction func logInAction(_ sender: Any) {
myButtonPressed()
}
#IBAction func sendPhotoAction(_ sender: Any) {
print("Button Pressed")
let fileData = UIImageJPEGRepresentation(myPhotoView.image!, 1.0)
//let compressedJPGImage = UIImage(data: fileData!)
let path = "/"
client?.files.upload(path: path, mode: .overwrite, autorename: true, clientModified: nil, mute: false, input: fileData!).response{ response, error in
if let _ = response { // to enable use: if let metadata = response {
print("OK")
} else {
print("Error at end")
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func myButtonPressed(){
DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: {(url:URL) -> Void in UIApplication.shared.openURL(url)
})
}
}
if your client is nil, then you aren't logged in. Try logging in and doing it again. Otherwise it should work fine.
https://dropbox.github.io/SwiftyDropbox/api-docs/latest/index.html#configure-your-project

thread1: exc_bad_instruction on swift

I do have error Thread1: EXC_BAD_INSTRUCTION. Been trying very hard on this. Any helpful personnel out there?
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var filePathUrl: NSURL!
var audioPlayer: AVAudioPlayer?
var receivedAudio:RecordedAudio!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
audioPlayer = try! AVAudioPlayer(contentsOfURL: receivedAudio.filePathUrl)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func playFastAudio(sender: UIButton) {
audioPlayer!.stop()
audioPlayer!.rate = 1.5
audioPlayer!.currentTime = 0.0
audioPlayer!.play()
}
#IBAction func playSlowAudio(sender: UIButton) {
// play audio slow
audioPlayer!.stop()
audioPlayer!.rate = 0.5
audioPlayer!.currentTime = 0.0
audioPlayer!.play()
}
#IBAction func StopButtonSound(sender: UIButton) {
audioPlayer!.stop()
}
}

Swift Barcode Scanning

I am attempting add barcode scanning to my app using RSBarcodes. I'm having two issues: Not being able to update a label that displays the barcode scanned and the delegate to send the barcode to my calling view controller not working. Below is my code for the view controller that handles the scanning:
import UIKit
import AVFoundation
import RSBarcodes
class ScanViewController: RSCodeReaderViewController {
#IBOutlet weak var label1Label: UILabel!
#IBOutlet weak var label2Label: UILabel!
#IBOutlet weak var scanLabel: UIButton!
var delegate: barcodesScannedDelegate?
var codes:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
var code=""
// Do any additional setup after loading the view.
focusMarkLayer.strokeColor = UIColor.redColor().CGColor
cornersLayer.strokeColor = UIColor.yellowColor().CGColor
tapHandler = { point in
//println(point)
}
barcodesHandler = { barcodes in
for barcode in barcodes {
if !contains(self.codes, barcode.stringValue) {
self.codes.append(barcode.stringValue)
code = barcode.stringValue
}
}
println(code)
self.label1Label.text = code
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func finishedPressed(sender: UIButton) {
delegate?.barcodesScanned(self.codes)
self.dismissViewControllerAnimated(true, completion: nil)
}
#IBAction func cancelPressed(sender: UIButton) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
Just to ensure I did the delegate correctly, here is my code in Protocol.swift:
protocol selectCarrierDelegate {
func selectCarrier(carrierID: String,carrier: String)
}
protocol barcodesScannedDelegate {
func barcodesScanned(barcodes: [String])
}
And the relevant code in the controller that should receive the barcode:
class InBoundViewController: UIViewController,selectCarrierDelegate,UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource,barcodesScannedDelegate {
func barcodesScanned(barcodes: [String]) {
println("codes=\(barcodes)")
}
Anyone have any ideas why the label won't change and the delegate isn't working?
You need to update all UI in the main thread.
Try this:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.label1Label.text = code
})
Swift 4:
DispatchQueue.main.async {
self.label1Label.text = code
}

Swift If Statement Not Working with UILabel

My if statement is not displaying what I want it to. Can anyone help? I want to display some text in a UILabel that will be decided from weather the random number is below or above 50.
Here is the code. The IF Statement is at the end.
import UIKit
import AVFoundation
class ViewController: UIViewController {
var pianoSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("two_tone_nav", ofType: "mp3")!)
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
audioPlayer = AVAudioPlayer(contentsOfURL: pianoSound, error: nil)
audioPlayer.prepareToPlay()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBOutlet weak var Number: UILabel!
#IBOutlet weak var BA50: UILabel!
#IBAction func Generate(sender: AnyObject) {
audioPlayer.play()
var Generate = Int(arc4random_uniform(100))
Number.text = String(Generate)
func AboveBelow50(){
if Generate>=50 {
self.BA50.text = "No"
}
else {
self.BA50.text = "Yes"
}
}
}
}
Put your function:
func AboveBelow50(Generate: Int){
if Generate>=50 {
self.BA50.text = "No"
} else {
self.BA50.text = "Yes"
}
Out side your IBAction, and change it this way.
And call inside your IBAction:
var Generate = Int(arc4random_uniform(100))
AboveBelow50(Generate)

Resources