loadHTMLString and "thread 1 exc_bad_access (code=exc_i386_gpflt)" - swift

Well, I'm not sure it is a real problem but it is unpleasant to see an error. The "thread 1 exc_bad_access (code=exc_i386_gpflt)" error appears with a probability of about 50% in simulator. But there is no error in real device.
I tried to use optionals, but without a noticeable result.
I have only WKWebView and a Button. The code is:
import UIKit
import WebKit
class ViewController: UIViewController {
#IBOutlet weak var WebView: WKWebView!
let all = ["kjhgjhkg","qqqqqqqqq", "wwwwwwwww", "lllllllll", "bbbbbbbb"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
WebView.loadHTMLString("<h1>The first title</h1>", baseURL: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func btnRefresh(_ sender: UIButton) {
let RandomNomber = Int(arc4random_uniform(UInt32(all.count)))
// let myString = all[RandomNomber]
// let myString2 = "<h1>" + myString + "</h1>"
WebView.loadHTMLString("<h1>" + all[RandomNomber] + "</h1>", baseURL: nil)
}
}

Related

elcimagepickercontroller in swift

I am using xcode 7.2 and Swift 2.1.1. I am using ELCImagePickerController through bridging header. When I use ELCImagePickerControllerDelegate in class declaration,it shows error- the viewcontroller does not conform to protocol 'ELCImagePickerControllerDelegate'
let picker = ELCImagePickerController()
picker.maximumImagesCount = 5
picker.delegate = self
self.presentViewController(picker, animated: true, completion: nil)
This is my objective c header #import "ELCImagePickerController.h"
When I use this code on button click event it goes to empty view and not the gallery.Can anyone help me to overcome this error.
Thanks in advance.
Error - the viewcontroller does not conform to protocol 'ELCImagePickerControllerDelegate' because you have to implement below 2 delegate methods which are mandatory. ( Not optional )
func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {
}
func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {
}
Download whole working project
Working code
import UIKit
class ViewController: UIViewController, ELCImagePickerControllerDelegate {
var picker = ELCImagePickerController(imagePicker: ())
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
picker.maximumImagesCount = 5
picker.imagePickerDelegate = self
self.presentViewController(picker, animated: true, completion: nil)
}
func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {
}
func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
That black screen were coming because of
var picker = ELCImagePickerController()
Proper way is
var picker = ELCImagePickerController(imagePicker: ())

Adding address to web view

I try to add address in several ways, but it's not working all the time. Anybody know the right code?
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var Dziennik: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
let url = URL (string: "http://google.com")
let requestObj = URLRequest(URL: url!);
Dziennik.loadRequest(requestObj)
Just change this:
webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
for this:
Dziennik.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
The issue is the name of the property.

Remove done button in M13PDFKit swift

I'm using M13PDFKit and having a little problem. In the example the done button is not there, but when I try it shows. I don't know how to remove it. The done button looks like this. Im using Swift
in View controller just like this
import UIKit
import M13PDFKit
class ViewController: UIViewController {
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.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "NEXT" {
let viewer: PDFKBasicPDFViewer = segue.destinationViewController as! PDFKBasicPDFViewer
viewer.enableBookmarks = true
viewer.enableBookmarks = true
viewer.enableOpening = true
viewer.enablePrinting = true
viewer.enableSharing = true
viewer.enableThumbnailSlider = true
//Load the document (pdfUrl represents the path on the phone of the pdf document you wish to load)
let pdfUrl = "/Users/developer/Library/Developer/CoreSimulator/Devices/C8DC5F44-B2FC-4FC3-8E10-B87FC00791FA/data/Containers/Data/Application/047BE9AD-F43C-421E-B5B5-943B0C79B592/Documents/Yudi Seven.pdf"
let document: PDFKDocument = PDFKDocument(contentsOfFile: pdfUrl, password: nil)
viewer.loadDocument(document)
}
}
}
Goto PDFKBasicPDFViewer.m disable the line(line 247) that highlighted in the first image and run the project....
Output:

Swift Signal SIGABRT error while making countdown timer?

I am working on a countdown timer for my app that starts counting down from 15. This is my code:
//
import UIKit
class ViewController2: UIViewController {
#IBOutlet weak var Timer: UILabel!
var countd = 15
//
//
override func viewDidLoad() {
super.viewDidLoad()
let time = NSTimer(timeInterval: 1.0, target: self, selector: "updateCounter", userInfo: nil, repeats: true)
Timer.text = String(countd)
NSRunLoop.mainRunLoop().addTimer(time, forMode: NSDefaultRunLoopMode)
}
func updateCounter(timer: NSTimer) {
Timer.text = String(countd)
if (countd > 0){
Timer.text = String(countd--)
Timer.text = String(countd)
}
}
// Do any additional setup after loading the view.
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
However, when I run it, as soon as I get to the part with the timer I see the label flash 15 for a second but then it immediately crashes with the SIGABRT error. What can I do?
Change
selector: "updateCounter"
to
selector: "updateCounter:"
Please note that in Swift 2.2 it will become difficult to make this mistake (the compiler will warn), and in Swift 3 it will become impossible (string literal selector syntax will become illegal). You might want to update to Swift 2.2 now if you don't understand string literal selector syntax.

Swift http req. doesnt go through

//
// FirstViewController.swift
// XeGaming
//
// Created by Brodie Andrew on 6/14/15.
//
import UIKit
class FirstViewController: UIViewController {
#IBOutlet var Count: UILabel!
#IBOutlet var MainDisplay: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "http://creepertech.net/app/app_urlGrabber.php?url=http://xegaming.com")
let request = NSURLRequest(URL: url!)
MainDisplay.loadRequest(request)
// 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 rel(sender: AnyObject) {
let url = NSURL(string: "http://creepertech.net/app/app_urlGrabber.php?url=http://xegaming.com")
let request = NSURLRequest(URL: url!)
MainDisplay.loadRequest(request)
}
#IBAction func ch(sender: AnyObject) {
let url = NSURL(string: "http://creepertech.net/app/app_urlGrabber.php?url=http://ihasabucket.com")
let request = NSURLRequest(URL: url!)
MainDisplay.loadRequest(request)
}
}
the http req on this page and the second page of my app just produces a white blank screen, both of these pages point to xegaming.com, the app url grabber also processes the third and fourth page, both of which work
I think that you are missing the NSURLSession, here is a link of how to use the NSURLSession properly: Link
Hope this help! :D