Azure Mobile Services crash - ios

Using the ios WindowsAzureMobileServices.framework (v1.2.3) I get an [NSArray insertObject:atIndex] exception (object cannot be nil) in code I don't control when I use the following code to present a MSLoginController.
MSLoginController *loginController =
[self.client
loginViewControllerWithProvider:provider
completion:^(MSUser *user, NSError *error)
{
//some code
}];
[controller presentViewController:loginController animated:YES completion:nil];
Any one have ideas how to rectify? Or why this is occurring?

I expanded the stack trace when the crash occurs and discovered UIAppearance calls were in the stack when the UIViewController was presented. After some digging into our appearance customization code the following code causes the crash:
[[UIBarButtonItem appearance] setStyle:UIBarButtonItemStylePlain];
The Azure library uses the UIToolbar in a different manner than was used elsewhere in the app and produced the exception.

Related

The TWTRComposerViewController not showing in Iphone-X Landscape

I'm using TWTRComposerViewController to share video on twitter my landscape app, it is working fine in all other device's except iPhone-X , when i try to share video in iPhone-X then composer not showing and the App freezes out.
I'm using the below written code:
if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers])
{
dispatch_async(dispatch_get_main_queue(), ^{
TWTRComposerViewController *composer = [[TWTRComposerViewController emptyComposer] initWithInitialText:#"Testing" image:nil videoURL:url];
composer.delegate = self;
[self presentViewController:composer animated:true completion:nil];
});
}
else
{
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
dispatch_async(dispatch_get_main_queue(), ^{
TWTRComposerViewController *composer = [[TWTRComposerViewController emptyComposer] initWithInitialText:#"Testing" image:nil videoURL:url];
composer.delegate = self;
[self presentViewController:composer animated:true completion:nil];
});
} else {
NSLog(#"Error");
}
}
The glitch you are encountering with the TWTRComposerViewController is not your error, nor are you the only one dealing with this.
This is a bug in Twitter's SDK.
Looking into Twitter's recent activity / attention to their SDK it seems their interface packages are lagging ever since the new iPhone X release. I would expect this to be resolved sooner than later.
I guess the best temporary solutions would be to either force your controller into portrait mode during this process, disable rotation for the appropriate controllers, or (though perhaps too ugly) present this VC in portrait, and rotate the view. Nonetheless, hopefully Twitter updates their SDK soon.
Report this as a bug to Twitter on their developer forum to let them know about the issue, as they should eventually see the numerous posts of the same issue...

Cannot show modal ViewController in iOS7

I tried to show system defined viewcontrollers (MFMailComposeViewController, TWTweetComposeViewController,etc..) as a modal view.
But these viewcontrollers dosn't appear in iOS 7(these run in iOS5,iOS6).
Viewcontrollers created by me appear in iOS7(ex.HogeViewController).
I don't call presentViewController:animated:completion at viewDidLoad or viewWillAppear.
Does anybody have an idea?
Console logs:
init Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
or
_serviceViewControllerReady:error: Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
or
Unbalanced calls to begin/end appearance transitions for .
TWTweetComposeViewController(doesn't appear)
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc]init];
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result){
NSLog(#"Result : %d",result);
};
[self presentViewController:viewController animated:YES completion:NULL];
Log
Result : 0
MFMailComposeViewController(appears a moment and dismiss soon)
- (void)send:(NSString*)email{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = #[email];
[picker setToRecipients:toRecipients];
[picker setSubject:#"Subject"];
[picker setMessageBody:#"Body" isHTML:NO];
[self.navigationController presentViewController:picker animated:YES completion:NULL];
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"error:%#,result:%d",error.description,result);
}];
}
Log
_serviceViewControllerReady:error: Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
Unbalanced calls to begin/end appearance transitions for .
error:(null),result:0
Turns out the issue only shows up when customizing UIBarButtons. If we use the following in our 32-bit app running on iPhone 5s, we have the problem:
[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, 1.0)
forBarMetrics:UIBarMetricsDefault];
Leaving out that line works around the problem. We have filed a radar.
This is an issue when you do not compile for 64bit (arm64) in your project settings. Though this may not always be an option for some people because currently Google Analytics does not support the 64bit devices.
You may be able to avoid this issue with some subclassing. I was having the same issue, and in my case the culprit was:
[[UISearchBar appearance] setSearchTextPositionAdjustment:UIOffsetMake(15.0f, 0.0f)];
I was already using a subclass of UISearchBar anyway, so I changed that to:
[[KA_SearchBar appearance] setSearchTextPositionAdjustment:UIOffsetMake(15.0f, 0.0f)];
That's resolved the issue for me. Only tested on an iPhone 5s, iOS 7.0.3.
I am getting the same behavior in the same situations. In my case it turned out to be caused by using the "setSeparatorInset" appearance selector of UITableView. Getting rid of that fixed the problem. This looks like a bug on Apple's end for sure, but at least there is a workaround.
This question shows someone having a similar problem and in their case getting rid of a UISearchBar appearance selector fixed it. So something is wrong with some of these UIAppearance selectors.
This post helped me find a solution to a similar issue. But my problem was not related to the tab bar, so I figured I'd share if anyone else comes across this post:
The mail modal opened when tapping a table cell, but would instantly dismiss. In my case, this code caused the problem:
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setFont:[UIFont systemFontOfSize:17.0]];
I deleted it, and everything works!
In My case, following code will cause the same issue on 64bit machine or simulator. Hope for helping someone met this issue.
if ([UITableViewCell instancesRespondToSelector:#selector(setSeparatorInset:)]) {
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];
}
This Problem occurs in iPad air (64 bit) when app is not complied for 64 architecture. The problem I encountered was every UIAppearance selector which try to use UIOffsetMake/UIOffsetZero doesn't work properly!
example
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(1.0, 1.0) forBarMetrics:UIBarMetricsDefault];
or
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsMake(0, 5, 0, 5)];
I think its a bug in Apple code and I tried few things but nothing works. Better if you can comment out places where you setInsets in UIAppearance selectors
I had the same error when use SLComposeViewController to share with Facebook or Twitter using the simulator of 64-Bits or an iPhone 5s, then i delete every line of code that use "appearance, for example [UITableViewCell appearance] or [UIBarButtonItem appearance], and every run ok.
I updated xcode to version 5.1 and it worked ok now.
NSXPCConnectionInterrupted = 4097. I would have your code retry the command as the error looks to be transient.

Error while dismissing UITableViewController

I have been creating a project and I am getting a warning from the debugger:
Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
Here is the code:
if (self.editHw)
{
if (self.homeworkEdit)
{
[self.homeworkEdit setValue:self.homeworkNameTF.text forKey:#"name"];
[self.homeworkEdit setValue:self.subject forKey:#"subject"];
[self.homeworkEdit setValue:self.dateDueLabel.text forKey:#"due_date"];
[self.homeworkEdit setValue:self.reminderDateLabel.text forKey:#"reminder_date"];
[self.homeworkEdit setValue:self.commentsTF.text forKey:#"comments"];
NSError *error = nil;
[context save:&error];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Can anyone tell me what the error means and why it is there? If you need any more info just ask.
The code you show isn't enough to know what the error is. The error is shown because you are trying to animate 2 different view controllers at the same time (one being dismissed and one being shown). To avoide the issue you can:
1. Wait until one animation is complete before starting the next
Or
2. Run one of the changes (probably the dismissal) without animation

Inconsistent crash while posting to facebook using FBNativeDialogs on iOS6.0

I've been struggling with this issue for a while now and I just can't seem to reproduce it accurately enough to describe the exact use-case. Essentially, what I'm doing is issuing a request for opening a native iOS 6.0 Facebook share dialog (using the Facebook iOS SDK 3.1.1):
if ([[SocialManager sharedManager] isNativeFacebookShareDialogAvailable]) {
if (!url) {
url = [NSURL URLWithString:#""];
}
if (!imageUrl) {
imageUrl = [NSURL URLWithString:#""];
}
dispatch_async(backgroundQueue, ^{
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];
if (!image) {
image = [[UIImage alloc] init];
}
if ([FBNativeDialogs canPresentShareDialogWithSession:[FBSession activeSession]]) {
dispatch_async(dispatch_get_main_queue(), ^{
[FBNativeDialogs presentShareDialogModallyFrom:sender initialText:initialText images:#[image] urls:#[url] handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
failBlock([[error userInfo] description]);
} else {
if (result == FBNativeDialogResultSucceeded) {
completionBlock();
} else if (result == FBNativeDialogResultCancelled) {
failBlock(#"User cancelled");
} else if (result == FBNativeDialogResultError) {
failBlock(#"Unknown error");
}
}
}];
});
} else {
LogErr(#"Can't display native share dialog for active session");
}
});
}
Right after presentShareDialogModallyFrom:sender is called, I either get the following crash log:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x1d161490> was mutated while being enumerated.'
*** First throw call stack:
(0x32ede2a3 0x326b097f 0x32eddd85 0x35da094d 0x32edb62f 0x35da07f5 0x35e7e5e5 0x35e0ccd7 0x35e0cb6d 0x372c490f 0x35e0ca61 0x35e160d5 0x372b783b 0x35e160b1 0x372b711f 0x372b699b 0x372b6895 0x372c5215 0x372c53b9 0x36f5fa11 0x36f5f8a4)
libc++abi.dylib: terminate called throwing an exception
OR I get no crash and the native share dialog appears as it should.
The stack implies a call on a thread called UIRemoteViewControllerCreationRequest at this point, here are 2 examples for two different crashes:
Thanks for your help
After a lot of experimenting with my application and looking into Facebook SDK source I realized 3 things:
Creating a SLComposeViewController by yourself doesn't help. Facebook SDK is pretty simple in this, it just creates the controller exactly like the code in the answer with bonus.
When you are authorizing the FB session, your application is deactivated once or more times. This is caused by the permission confirmation alerts appearing.
The UIRemoteViewController is actually the SLComposeViewController which is run in a different process.
What caused my error?
User confirms FB permissions
This triggers applicationDidBecomeActive:
It also triggers FB callback to present the dialog.
My applicationDidBecomeActive: was doing something with the UI what was not supposed to be done when the FB dialogs were appearing (tirggering a table reload).
Also, there is another thing to be careful of - the handler of presentShareDialogModallyFrom... is not called on any particular thread (see SLComposeViewController docs). That means that you should use dispatch_async(dispatch_get_main_queue(), ...) from the handler if you are updating UI from it.
EDIT:
Obviously, the previous steps fixed some crashes but one of the crashes was not solved. After a lot of googling and searching Apple Developer forums, I think there is a bug in iOS 6 connected with Remote Controllers and using UIAppearance, especially the appearance of UINavigationBar. I am currently removing the use of UIApperance from my app.
This is a very strange way to post a post to Facebook. Here is a much simpler way that never crashes.
ViewController.h
#import <UIKit/UIKit.h>
#import <Social/Social.h>
#import <Accounts/Accounts.h>
#interface ViewController : UIViewController {
SLComposeViewController *mySLComposerSheet;
}
- (IBAction)PostToFacebook:(id)sender;
#end
ViewController.m
#implementation ViewController
- (IBAction)PostToFacebook:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Place Text Here"];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
#end
If needed, there is a video here.
Sorry some of this is rather guessing, but I thought I would try:
Are you sure that canPresentShareDialogWithSession is safe to call from a non-UI thread?
You have a line in both stacks of _NSDictionaryEnumerate. It looks like from higher functions, that something is calling enumerateKeysAndObjectsUsingBlock:.
Based on your note of things crashing just after [presentShareDialogModallyFrom:sender]. Is there something being released when sender's view disappears?
Variable "image" is either retained or autoreleased depending on which code path it took.
I think the problem is what Walt already said. In your code, something is done outside the main thread.
In the crash log you can see that someone is setting the appearance (UIAppearance) on some UI element from a non-UI thread. That's the problem. This operation MUST be done ONLY in the UI (main) thread.
I believe this has to do with the combination of the UIAppearance methods and launching a UIRemoteViewController from a background thread. We're having the same issue in our app. I'm going to change our presenter class to present all our remote viewControllers from the main thread and see if that helps.
In your case, I guess something in the Facebook SDK is presenting something from a background thread.
I'll update after I've verified that my fix works.
This is a bug in iOS 6 and Social Framework, check answer here UINavigationBar appearance and Facebook-Sheet Bug
How to solve this?
Simply instead of using [UINavigationBar appearance] use [UINavigationBar appearanceWhenContainedIn:...]
You can use custom class for your navigation controller (eg. CustomNavigationController) and then apply it in appearance:
[UINavigationBar appearanceWhenContainedIn:[CustomNavigationController class], nil]
From my experiments it should be used on all appearance methods, not only UINavigationBar but also UIBarButtonItem etc. (on every object you send appearance message to)
I think you know what is obvious but I met this error once and it was an NSMutableArray that was mutated while being enumerated inside a for..in statement.
Look at the NSMutableArray, you'll find your error.
Byt the way, if you target ios6, why don't you use the social framework with native facebook implementation ?

How to debug on the iPhone itself without xcode? UISearchBar/DisplayController crashes

I have a problem: I am programming an app that is using a searchBar and a tableView.
When I click the search bar, type some string to search for, as soon as I hit the cancel button, or delete all the search terms and click the tableView again my app crashes.
When I run the app in the iOS Simulator, it doesn't crash when doing this.
When I run the app on my iPhone via xcode, it doesn't crash when doing this.
I don't really understand the device log and I wanted to ask if there is any way to find out what's going terribly wrong and why this is not happening when doing it via xcode. Please help me!
PS: One of the device logs: (Maybe you guys understand this)
EDIT: Here's the code of the searchDisplayControllerDidEndSearch method:
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
[UIView beginAnimations:#"DeactivateSearch" context:nil];
[UIView setAnimationDuration:0.4];
[self.attractionsTableView setFrame:CGRectMake(0, 43, 320, 362)];
[UIView commitAnimations];
NSFetchRequest *fetchRequest = [[self fetchedResultsController] fetchRequest];
[fetchRequest setPredicate:nil];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
// Handle error
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
[self setSearchIsActive:NO];
return;
}
UPDATE: The search bar does NOT crash if no text was typed. So simply activating the searchBar and deactivating it without typing works. But as soon as I have typed a single character the deactivating process crashes the app.
Look for an animation callback issue. Also there is a console log, look at it.
I found the answer myself..
In one of my custom cells I released something too often and thus the app crashed when the UISearchDisplayController was releasing the UITableView for the search results.

Resources