I still can't figure my simple do,try catch at json parsing causing google analytic compile time error.
Especially at theses :
let tracker = GAI.sharedInstance().defaultTracker
let event = GAIDictionaryBuilder.createEventWithCategory("Home Screen", action: "Tapped", label: "User tapped one of content from Home Content Area 2", value: nil)
tracker.send(event.build() as [NSObject : AnyObject]) // Show me error at this
All I did was adding my do,try catch at RequestSuccess[When getting response from server,parse json to model object] delegate method.
Any Help,do I need to add some info extras?
When I remove do,try,catch,that error gone.Do my do,try,catch concern with that error?
It's not obvious, but I don't think the do, try, catch is the issue. Try:
tracker.send(event!.build() as [NSObject : AnyObject])
You may also need to unwrap the tracker with tracker?.send... etc.
Related
I am playing with Vision for text recognition, I present the camera, take a photo and the text is detected and processed...running very well. The issue I have is when there is no text in the photo, I get an error from VNImageRequestHandler, which is fine, but the issue is that I can't re-open the camera, I get "Warning: Attempt to present UIImagePickerController: ... while a presentation is in progress!.
here is some code where I process the image looking for some text...
guard let image = image, let cgImage = image.cgImage else { return }
let requests = [textDetectionRequest]
let imageRequestHandler = VNImageRequestHandler(cgImage: cgImage, orientation: .up, options: [:] )
DispatchQueue.global(qos: .userInitiated).async {
do {
try imageRequestHandler.perform(requests)
} catch let error {
print("Error: \(error)")
}
}
}
the Error is
"Error: Error Domain=com.apple.vis Code=11 "encountered unknown
exception" UserInfo={NSLocalizedDescription=encountered unknown
exception}"
which is fine, I just want to be able to open the UIImagePickerController after that Error.
I have tried to dismiss the UIImagePickerController, does not work... and I can't find what presentation is really in process.
Thanks.
For me it was something completely unrelated that caused this error. After the VNRequestCompletionHandler was called, I attempted to initialize a malformed NSPredicate. Then I would get the error that you described. Fixing the predicate also fixed the issue you described.
I would look to see if there's any work you're doing after the completion handler is called that can throw an error and fix that.
I am trying to send custom dimensions as data from my app to the google analytics dashboard. I have successfully got screenviews and events showing in Google Analytics.
Below is my code for sending the custom dimension
func logScreenTrackingWithCustomDimension(screenName: String, data: AnyObject) {
let customDimension = data
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(GAIFields.customDimensionForIndex(1), value: customDimension as! String)
tracker.set(kGAIScreenName, value: screenName)
tracker.send(GAIDictionaryBuilder.createScreenView().set(customDimension as! String, forKey: GAIFields.customDimensionForIndex(1)).build() as NSDictionary as [NSObject : AnyObject])
}
the function argument "data" is the string value I am passing in from another controller where I call this function.
I have also set up the dimension correctly within google analytics
P.S i am tracking screenviews and events for the above code and they show up in google analytics. Just not the actual data of the dimension which is not being tracked for some reason
Any help would really be appreciated because I am trying to track a product ID when click on a product screen. This will enable me to see what products are being viewed etc.
Thanks
For dimensions, use this:
let customDimension = data as! String
tracker.set(GAIFields.customDimension(for: UInt(indexNo)), value: customDimension)
So I'm trying to create a user on my database backend, everything is working on the app bar this segment on xcode, written in swift.
The backend can accept new users via this method but for some reason swift won't have it.
When I click register I get the error shown in the photo, code used
Alamofire.request(.POST, urlRequest, parameters: ["X-API-KEY": API_GENERAL_KEY,"username":userName.text!,"email": userMail.text!,"password":userPassword.text!,"profile_photo": self.imageName])
and the output is
<spotimusic.RadioStyleCollectionViewController: 0x7fe313d8fd00> whose view is not in the window hierarchy!
SDSD - Optional("nathan#trojan-audio.com")
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
Another error which shows in a segment is
Thanks for any help or suggestions
It seems that userName.text or userPassword.text doesn't have a value. This error can occur due to an unlinked outlet.
If your outlets are linked properly try this:
guard let userName = userName.text, let userMail = userMail.text, let userPassword = userPassword.text else {
return
}
Alamofire.request(.POST, urlRequest, parameters: ["X-API-KEY": API_GENERAL_KEY,"username":userName,"email": userMai,"password":userPassword,"profile_photo": self.imageName])
You will be able to catch the empty values without crashes.
Let me know if it fixes your problem
Thanks for all of the help guys, Marco's answer was the one that I used that fixed all the errors.
guard let userName = userName.text, let userMail = userMail.text, let userPassword = userPassword.text else {
return
}
Alamofire.request(.POST, urlRequest, parameters: ["X-API-KEY": API_GENERAL_KEY,"username":userName,"email": userMai,"password":userPassword,"profile_photo": self.imageName])
Facing an issue with xcode.
I'm trying to develop an app that gives me the weather info. The build succeeds, but everytime I click on the console to check the output (to search, copy etc) xcode crashes.
The following text comes from the reporting tool to Apple,
Application Specific Information:
ProductBuildVersion: 7C1002
UNCAUGHT EXCEPTION (NSRangeException): -[__NSCFString characterAtIndex:]: Range or index out of bounds
UserInfo: (null)
Hints: None
Here's the code I'm running,
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string:"http://www.weather-forecast.com/locations/Hyderabad/forecasts/latest")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) -> Void in
if let webContent = data {
let decodedContent = NSString(data: webContent, encoding: NSUTF8StringEncoding)
//print(decodedContent)
let weatherSiteSourceArray = decodedContent?.componentsSeparatedByString("3 Day Weather Forecast Summary:</b><span class=\"read-more-small\"><span class=\"read-more-content\"> <span class=\"phrase\">")
print(weatherSiteSourceArray)
// if weatherSiteSourceArray?.count > 0 {
//
// let weatherInfo = weatherSiteSourceArray![1]
// print(weatherInfo)
// }
}
}
task.resume()
// Do any additional setup after loading the view, typically from a nib.
}
though the report tool informs me UNCAUGHT EXCEPTION (NSRangeException): -[__NSCFString characterAtIndex:]: Range or index out of bounds.
I am unable to figure out where this is happening.
From what i have learned you can print an array in Swift using the print(items: Any...) method.
help on this would be greatly appreciated !
You are checking is there any element in your array and then you are trying to read second element. There are chances that your array is having only one item in it and hence when you are choosing weatherSiteSourceArray![1], it fails as accessing element 2 is out of bound of array.
if weatherSiteSourceArray?.count > 0 {
let weatherInfo = weatherSiteSourceArray![1]
Either check for
if weatherSiteSourceArray?.count > 1
or use first element i.e.
let weatherInfo = weatherSiteSourceArray![0]
I have no idea of swift and assume it uses zero based index for array.
A good place to start would be to figure out exactly which line is causing the crash. Try commenting out these three lines:
let decodedContent = NSString(data: webContent, encoding: NSUTF8StringEncoding)
//print(decodedContent)
let weatherSiteSourceArray = decodedContent?.componentsSeparatedByString("3 Day Weather Forecast Summary:</b><span class=\"read-more-small\"><span class=\"read-more-content\"> <span class=\"phrase\">")
print(weatherSiteSourceArray)
And if you code doesn't crash after that, then try commenting in you code one line at the time until you have the line crashing.
Another thing:
Looking at your code I'm guessing that maybe this line:
let weatherSiteSourceArray = decodedContent?.componentsSeparatedByString("3 Day Weather Forecast Summary:</b><span class=\"read-more-small\"><span class=\"read-more-content\"> <span class=\"phrase\">")
might be the one causing your problems. Its a bit risky and brittle to try separating your content based on an HTML string like that. The second that string changes (and it will :-)), you've lost.
A better way would be to receive the data in pure JSON or XML if they have an API providing that.
Just a thought :-)
I am working on developing my first ResearchKit App. I have been watching this video. One of the techniques used that is going to be helpful for me is serializing the results of a survey to JSON. The method used in the video is ORKESerializer.JSONDataForObject(taskResult). He explains that this is not a standard part of researchKit, but it was included in a test app, called ORKTest that is on GitHub.
I set up my taskViewController delegate just like he had it set on the video, like this:
extension ViewController : ORKTaskViewControllerDelegate {
func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
switch reason {
case .Completed:
let taskResult = taskViewController.result
let jsonData = try! ORKESerializer.JSONDataForObject(taskResult)
if let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding) {
print(jsonString)
}
break
case .Failed, .Discarded, .Saved:
break
}
//Handle results with taskViewController.result
// let taskResult = taskViewController.result
taskViewController.dismissViewControllerAnimated(true, completion: nil)
}
}
I am getting this error upon compiling : use of unresolved identifier: ORKESerializer
So in the ORKTest app, in the GitHub files, I found 2 files. One called ORKESerialization.h, and one called ORKESerialization.m. I tried dragging those into my project, as I saw those files in the man's project in the video. And then that also prompted me to create a bridging header file as well, which I also saw in his project.
After doing that I am still getting the same error. The truth is I don't know exactly how to include these serialization packages with my app. Does anyone know how to included the right files so that I can implement this ORKEserialization method?
Thanks!
You need to import ORKESerialization.h in your bridging header:
#import "ORKESerialization.h"