Google Autocomplete function Crash after Call - ios

I am using Google PlaceAutoComplete method to get suggestions of the Addess that is entered in textField.
func placeAutocomplete(text:String) {
let placesClient = GMSPlacesClient()
let filter = GMSAutocompleteFilter()
filter.type = .Address
placesClient.autocompleteQuery("New Delhi", bounds: nil, filter: nil) { (results, error) in
guard error == nil else {
print("Autocomplete error \(error)")
return
}
self.addressArray.removeAll()
for result in results! {
self.addressArray.append(result.attributedFullText.string)
print("Result \(result.attributedFullText.string) with placeID \(result.placeID)")
}
}
}
When i call this method. It crashes, say the Following error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary boolValue]: unrecognized selector sent to instance 0x7fe338f01e40'
I have tried to found using exception breakpoint but doesn't work.
Can any have idea, where i am wrong?

I have resolved the issue by correcting in the plist for "allow arbitrary loads" in App Transport security Settings. I was typed it true but its type was set string instead for Boolean

Somewhere a NSDictionary is being passed to the code where it is expecting a something that can be interpreted as a boolean such as an NSString or NSNumber. I don't see anything like that in the code you provided. If exception breakpoints aren't working I would try adding normal breakpoints somewhere and stepping over code until it crashes. You could also try removing certain sections and code and seeing if the crash is still happening, this will let you narrow down what portion of your code is to blame.

Related

pesky problem: IsFormatSampleRateAndChannelCountValid(format) error in IOS simulator

I keep getting this pesky error on init sometimes. It occurs for a while and sometimes it goes away. I am not sure what is the problem. Please help. Details below
Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
The stack trace points to this piece of init() code.
init() {
guard let AK52_input = AK52_engine.input else {
fatalError()
}
do {
AK52_recorder = try NodeRecorder(node: AK52_input)
} catch let err {
fatalError("\(err)")
}
let silencer = Fader(AK52_input, gain: 0)
self.AK52_silencer = silencer
AK52_mixer.addInput(silencer)
AK52_mixer.addInput(AK52_player)
AK52_engine.output = AK52_mixer <----- error pops from here
}
And this code is identical to the one in the AudioCookbook. Infact, I see the same error when I run AudioCookbook too.
Please help.
thanks,
-Vittal

Receiving EXC_BAD_ACCESS exception

I am using a singleton class to select data from CoreData, and send it back to the calling ViewController. My issue is that when getting one of the ManagedObject's properties, the app crashes with an EXC_BAD_ACCESS exception.
This only seems to happen on iOS 9.x or on the simulator, but is pretty consistent on those. It hasn't happened on a device running 10.x. I set the scheme diagnostics to show zombie objects, and am now presented with the following error:
-[CFString copy]: message sent to deallocated instance 0x15b92990
The issue is that the string being referenced is on an object retrieved directly before I get this error, and I am using Swift (So not manually deallocating anything), so I don't understand why it is deallocated.
The code that selects the object looks like this:
func getModelTypePrice(mmCode: String, year: Int) -> ModelTypePrice? {
let request = NSFetchRequest<ModelTypePrice>(entityName: "ModelTypePrice")
request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [NSPredicate(format: "mmcode = %#", mmCode),
NSPredicate(format: "reg_year = %d", year)])
do {
let prices = try managedContext.fetch(request)
if prices.count == 1 {
return prices[0]
}
} catch {
print("Error selecting object: \(error)")
}
return nil
}
That is called from the ViewController, and used as follows:
if let price = LibraryAPI.sharedInstance.getModelTypePrice(mmCode: "123", year: 2017) {
self.newPrice = price.new_price // Error happens here.
}
The ViewController does have an optional String property called newPrice. The new_price property on a ModelTypePrice is also an optional String.
I am at a bit of a loss here, so any advice or suggestions would be appreciated.
This fixed it: [CFNumber release]: message sent to deallocated instance
The problem was the name of the property of the managed object starting with new(it was new_price). Changing it to price_new fixed it. Apparently they changed how this is handled in iOS 10.x, as it was never a problem there.
Maybe this saves someone else some frustration.

AppleWatch - "attempt to insert nil" when calling WKInterfaceDevice addCachedImage

Calling WKInterfaceDevice addCachedImage(_:name:) to send an image from my iPhone app to the Apple Watch (where the extension can tell an image view to show it) crashes. The exception is this:
2015-06-09 20:47:57.079 TimeInterval[20195:5186462] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[3]'
Various Google and StackOverflow searches show this has to do with using a shortcut to create an NSDictionary that doesn't allow passing in nil. However, my code isn't making a dictionary at all. Furthermore, when the debugger breaks (breakpoint on exceptions) I verify that the UIImage and the NSString name that I am passing are both definitely not nil.
Has anyone else seen this? Any idea why it happens or how to fix it? Has anyone actually been successful using addCachedImage? (Considering how new AppleWatch is, who knows!)
My chunk of code, in case it helps:
func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {
if let info = userInfo {
NSLog("watch kit request: %#", info)
if let element = info["element"] as? String {
//Request to render an element
if element == "timer" {
let timerView = NPProgressLabel(size: CGSizeMake(48, 48))
timerView.text = info["value"] as! String
timerView.progressPercent = (info["progress"] as! NSNumber).floatValue
timerView.render()
let device = WKInterfaceDevice.currentDevice()
var success = false
if let image = timerView.currentImage {
success = device.addCachedImage(image, name: timerView.currentImageName()) // <------- crashing here ----------
} else {
NSLog("no image");
}
if !success {
NSLog("failed")
} else {
NSLog("addCachedImage success")
}
reply(["imageName": timerView.currentImageName()])
} else {
reply(["error": "Unknown element"])
}
return
}
}
reply(["error": "Bad request"])
}
The exact error I get may be an Apple bug, but I think the answer to my question is that WKInterfaceDevice's addCachedImage should not be called from the iPhone app but rather from the WatchKit Extension. Between iPhone app and WatchKit Extension I have to use a shared container to save then load the image, then the extension can call addCachedImage.

Swift: Key has no data exception, despite checking for nil

I'm scratching my head over this one, I thought the whole point of checking for nil was to ensure unsafe variables were ignored at run-time allowing the app to not crash.
I have tried to check the key returned from the server for nil, and also tried optional chaining to test for nil, neither are working and I still get the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "avatar" has no data. Call fetchIfNeeded before getting its value.'
I understand this means that no data was found for the avatar key, but due to the tests I am running I'm confused why this error is even being raised
for var i = 0; i < recipients.count; i++
{
if let u = recipients[i] as PFUser!
{
if u.valueForKey("avatar") != nil
{
println(i)
}
}
}
Conversely, I tried to optional chain the result of the image:
if let image: UIImage = UIImage(data: (u["avatar"]!.getData() as NSData?)!) {}
Both times the application will crash throwing the exception stated above. My stack trace shows nothing else which is of use, however the println statement will print 0, 1 and then crash on element 2 (where the collection size is 4 so I am not out of bounds).
Any ideas on how I can fix this?

Send a log to Crashlytics without an app crash

How can I get Crashlytics to receive a log without my app crashing?
I have the following code:
if(!context.managedObjectContext save:&error) {
CLS_LOG(#"%#",error.description)
}
When an error occurs, I want the Crashlytics server to receive the error but the app should continue running.
I do not need the log right away. I would be happy to get the log on the next restart. I just do not want to have to trigger a crash in my app to receive the log.
Is this possible?
With the new update from crashlytics you can now use:
[[FIRCrashlytics crashlytics] recordError:error];
And in Swift:
Crashlytics.crashlytics().record(error: error)
You can check the documentation here.
Kinda old question, but now you can use Answers which is part of the Fabric suit (Crashlytics is part of Fabric as well):
Fabric can be found here. And further documentation here.
I tried the below lines and it works like charm. In try-catch block use the below lines in your catch block
#try {
// line of code here
}
#catch (NSException *exception) {
NSUncaughtExceptionHandler *handler = NSGetUncaughtExceptionHandler();
handler(exception);
}
as explained at http://support.crashlytics.com/knowledgebase/articles/222764-can-i-use-a-custom-exception-handler
[UPDATE]
Now in fabric's crashlytics we can use simple function [Crashlytics recordCustomExceptionName:reason:frameArray:] for sending handled exceptions
#try {
// line of code here
}
#catch (NSException *exception) {
NSArray *stack = [exception callStackReturnAddresses];
[[Crashlytics sharedInstance] recordCustomExceptionName: exception.name
reason: exception.reason
frameArray: stack];
}
as explained at
https://twittercommunity.com/t/crashlytics-ios-how-to-send-non-fatal-exceptions-without-app-crash/34592/32
For me the method .recordError() didn't helped, because it don't log the user information. Or i just didn't found where to watch it. Using recordCustomExceptionName fit to me. There is an example of implementation of the both ways:
func logMessage(_ message: String) {
let userInfo = ["message" : message]
let error = NSError(domain: "AppErrorDomain", code: 1, userInfo: userInfo)
Crashlytics.sharedInstance().recordCustomExceptionName("API Error", reason: message, frameArray: [])
Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo: userInfo)
}
Swift 5, Crashlytics SDK 4.0.0-beta.6:
let exceptionModel = ExceptionModel(name: "exception title", reason: "details")
Crashlytics.crashlytics().record(exceptionModel: exceptionModel)
...similar for NSError, with whatever you want to see in the Crashlytics dashboard.
let error = NSError(domain: "error title", code: 0, userInfo: ["message":"some details"])
Crashlytics.crashlytics().record(error: error)
Crashlytics is a crash tracking service, if you need to track custom messages choose other analytics service.
In reference from Crashlytics documents.
try {
myMethodThatThrows();
} catch (Exception e) {
Crashlytics.logException(e);
// handle your exception here!
}
https://docs.fabric.io/android/crashlytics/caught-exceptions.html?caught%20exceptions#caught-exceptions
As far as I know, if you dont protect your code correctly, your application will crash anyway. Crashlylytics, take this crashes and show them to you in a "readable" mode in the web application they have designed. If there is no crash, crashlytics will take anything. You can grab an exception in your code :
#try{
....
}
#catch(NSException ex){...}
in the critical parts, but you should always do that if you are afraid your application is going to crash or you find a potential error which can allow your application have a bad behavior and acting up. You can always force in your exception to send or track this error.
Hope it helps
The trick is to use the following :
http://support.crashlytics.com/knowledgebase/articles/202805-logging-caught-exceptions
Just use this :
Crashlytics.logException(new Exception("my custom log for crashLytics !!!"));
I use this and I get my non-fatal crash in about 5 minutes !

Resources