"Thread 1: signal SIGABRT" error with JSON serialization - ios

I'm trying to parse weather data into my App with Xcode 7.3.1, iOS 9.3 and JSON by using Weather Underground API (but I get the same problem with other APIs such as OpenWeatherMap).
I don't get error when I build my app but when I call the weather in the Simulator I get a "Thread 1: signal SIGABRT" error. I used breakpoint to speculate that my problem come from the Serialization.
I have already tried to clean my project and I didn't have double connections.
When I download and run the project of this tutorial I have the same problem...
Here is my code :
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIButton *affichermeteo;
#property (weak, nonatomic) IBOutlet UILabel *meteo;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)affichermeteo:(id)sender {
NSData *allCoursesData = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:#"http://api.wunderground.com/api/e5cdee14984e242b/conditions/q/CA/San_Francisco.json"]];
NSError *error;
NSDictionary *allCourses = [NSJSONSerialization
JSONObjectWithData:allCoursesData
options:NSJSONReadingMutableContainers
error:&error];
if( error )
{
NSLog(#"%#", [error localizedDescription]);
}
else {
NSArray *currentobservation = allCourses[#"estimated"];
for ( NSDictionary *theCourse in currentobservation )
{
_meteo.text=theCourse[#"weather"];
}
}
}
#end
My error window :
Here
Thank you in advance for your help and sorry for my english, I am french !

I am able to get data using your code. You are missing the iOS 9's newly added App Transport Security flag.
Add the App Transport Security Settings key and mark Allow Arbitrary Loads to YES like in the screenshot below:
This should solve your problem.
Check this link to learn more about App Transport Security.

Related

Set NSObject property - EXC_BAD_ACCESS

Process :
App is on the home view controller and is requesting data on API to set an NSObject property. The request is processing on a private method.
User change the view controller to a second view controller (the request is still processing asynchronously)
The second view controller is loaded
The request is ending and app return EXC_BAD_ACCESS when it setting the object property
It seems the object has not the correct memory access.
I would like than the user can switch view controller, even if there is a request pending, and the application doesn't crash.
I don't want to block the user on the view controller during loading.
User.h
#interface User : NSObject
[...]
#property (nonatomic) NSString *notification;
[...]
-(void) methodName;
#end
User.m
-(void) methodName{
//there is code around but useless for this problem
[...]
NSError *error;
NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
self.notification = [[dict objectForKey:#"infos"] objectForKey:#"notification"]; //Here is the EXC_BAD_ACCESS
[...]
}
MyController.m
#interface MyController ()
#end
User *user;
#implementation HomeCVViewController
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
user = [User new];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[user someMethod];
dispatch_async(dispatch_get_main_queue(), ^{
[...]//some code
});
});
}
#end
EDIT :
I just put #property (nonatomic) User *user; in MyController.h and remove User *user; in MyController.m . The user is not deallocated and there is no crash.
Verify that [dict objectForKey:#"infos"] is not NSNull - Crash
can be here.
Other code looks OK.
Also add -(void)deallocto your object and put a
break point there to verify that the object is not being released
before the assignment.
Check your output at the NSError
NSError *error;
NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(#"%#", error.localizedDescription); <----- HERE
self.notification = [[dict objectForKey:#"infos"] objectForKey:#"notification"];
When you try to convert from/to JSON, improper JSON structure will cause it to crash. See the error for more information.
Usually, this type of error appears when object deallocated but your code try to access it's data
so, first of all, check how do you hold your User entity in memory, throw, for example, property:
#property (nonatomic, strong) User *u;
and make sure it is still in memory when operation completed:
Hope this will help you.
Instead of
self.notification = [[dict objectForKey:#"infos"] objectForKey:#"notification"]; //Here is the EXC_BAD_ACCESS
write
NSDictionary* infoDict = dict [#"infos"];
id notification = infoDict [#"notification"];
self.notification = notification;
set a breakpoint, and examine each of infoDict, notification, and self. That takes the guesswork out of it. Right now you don't even know which of these three assignments goes wrong.
And since you have lots of lines of code that are in your opinion bug free and irrelevant, chances are good that the actual bug is hiding somewhere in those lines. Remember: There is a bug in your code. Assuming that any of your code is bug free is daft, because you already know it isn't!

Unable to launch twitter api in my iOS program, error with Fabric

I recently tried to implement twitter login with my app, using Fabric.
While following their tutorial, I made a little change - instead of defining the TWTRLogInButton in my .m file, I defined it in my .h file first.
So in my .h file, I set the button like:
#property (strong, nonatomic) IBOutlet TWTRLogInButton *twitterButton;
And in my .m file the code is:
_twitterButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
NSLog(#"signed in as %#", [session userName]);
} else {
NSLog(#"error: %#", [error localizedDescription]);
}
}];
And it gives me an error like this:
"[Fabric] Unable to locate application icon"
And ever since I can't find a way to solve this.
I have tried changing the code exactly just as tutorial said as well, but it did not work either. I simply don't understand why Fabric is unable to locate my icon...
Any help is appreciated. Thank you in advance.

UIWebView iOS 8 Action Extension crash in iOS 8 mobile safari

View of iOS 8 action extension app has UIWebView. When I open this action extension in Safari and then extension app shows UIWebView of mobile Safari's URL.
But extension app crashes sometimes during loading web page or scrolling it for some web pages like nytimes.com.
I know extension app's usable memory depends on mobile Safari.
But I found that 'Awesome Screenshot for Safari' does not crash.
(https://itunes.apple.com/us/app/awesome-screenshot-for-safari/id918780145)
I am wondering how to prevent action extension app from crashing.
#interface ActionViewController ()
#property(strong,nonatomic) IBOutlet UIImageView *imageView;
#property (strong, nonatomic) IBOutlet UIWebView *webView;
#end
#implementation ActionViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
NSItemProvider *itemProvider = item.attachments.firstObject;
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
__weak typeof(self) weakSelf = self;
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(id<NSSecureCoding> item, NSError *error) {
if (error) {
[weakSelf.extensionContext cancelRequestWithError:error];
return;
}
if (![(NSObject *)item isKindOfClass:[NSURL class]]) {
NSError *unexpectedError = [NSError errorWithDomain:NSItemProviderErrorDomain
code:NSItemProviderUnexpectedValueClassError
userInfo:nil];
[weakSelf.extensionContext cancelRequestWithError:unexpectedError];
return;
}
NSURL *url = (NSURL *)item;
[weakSelf.webView loadRequest:[NSURLRequest requestWithURL:url]];
}];
} else {
NSError *unavailableError = [NSError errorWithDomain:NSItemProviderErrorDomain
code:NSItemProviderItemUnavailableError
userInfo:nil];
[self.extensionContext cancelRequestWithError:unavailableError];
}
}
I was experiencing the same issue, using a UIWebView in the background to scrape some content for my app. It worked fine when I was connected to the debugger. But running the same build without the debugger always crashed.
I resolved it by migrating to WKWebView, which was actually pretty easy. I guess UIWebView is just too old and inefficient to be running in an extension inside of Safari. Using WKWebView worked perfectly.
I then discovered a crash when I was done using the web view and was saving my data. I was saving it to NSUserDefaults (using my group container) to pass to the main app. This was always crashing too, so I removed that code. I ended up using CoreData instead, which worked fine too.
Now I have a crash free Safari extension! :)

Can someone explain to me how to download a file asynchronously from parse using PFFile?

Ive been stuck on this problem for a good while now, I read a bunch of threads but none describe my problem I tried a whole bunch of different methods to do it but none worked. I have a PFFile that I pulled from array and sent through a segue to a download detail view. This file is called "download file".I am trying to program a button when clicked to initiate the download. here is the code:
this is my download detail.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#interface PDFDetailViewController : UIViewController {
}
#property (strong, nonatomic) IBOutlet UILabel *PDFName;
#property (strong, nonatomic) IBOutlet UILabel *PDFDescription;
#property (strong, nonatomic) NSString* PDFna;
#property (strong, nonatomic) NSString* PDFdes;
#property (retain,nonatomic) PFFile * downloadfile;
- (IBAction)Download:(id)sender;
#end
my download detail button
- (IBAction)Download:(id)sender {
[self Savefile];
}
-(void) Savefile {
NSData *data = [self.downloadfile getData];
[data writeToFile:#"Users/Danny/Desktop" atomically:NO];
NSLog(#"Downloading...");
}
#end
and here is the segue that sends the download file:
detailVC.downloadfile=[[PDFArray objectAtIndex:indexPath.row]objectForKey:#"PDFFile"];
I get the array data using the PFQuery and store it into "PDFArray". This is a synchronous download because a warning message comes up when i click the button saying that main thread is being used. Although the file doesn't show up on my desktop.
Have you tried using this Parse method?
getDataInBackgroundWithBlock:
-(void) Savefile {
[self.downloadfile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (error) {
// handle error
}
else if (data) {
[data writeToFile:#"Users/Danny/Desktop" atomically:NO];
}
}];
}

iOS Pebble-Watch Launching & Killing "Self.connectedWatch"

When I read the sample code for Launching and killing your Pebble app:
[self.connectedWatch appMessagesLaunch:^(PBWatch *watch, NSError *error) {
if (!error) {
NSLog(#"Successfully launched app.");
}
else {
NSLog(#"Error launching app - Error: %#", error);
}
}
];
What that mean Self? How can I create something like self
in this code because I give the error the Property 'connectedWatch' not found on object of type.
Just look in the .h file and add this property between #interface and #end, like so:
#property (strong) PBWatch *connectedWatch;

Resources