Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

appearanceWhenContainedIn warning for ios 9

I have some warning which worked well in ios 7 & 8. While we work with iOS 9 its gives me a warning.

This is the warning :

'appearanceWhenContainedIn:' is deprecated: first deprecated in iOS 9.0 - Use +appearanceWhenContainedInInstancesOfClasses: instead

So I used this code :

[[UITextField appearanceWhenContainedInInstancesOfClasses:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

Instead of this code:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

But when I used I got the error:

Too many arguments to method call, expected 1, have 2

warning: 'base64Encoding' is deprecated: first deprecated in iOS 7.0

In below code:

 NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64Encoding]];

warning: 'searchDisplayController' is deprecated: first deprecated in iOS 8.0

In below code:

[self filterContentForSearchText:searchText scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                                   objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

warning: 'sendSynchronousRequest:returningResponse:error:' is deprecated: first deprecated in iOS 9.0 - Use [NSURLSession dataTaskWithRequest:completionHandler:] (see NSURLSession.h

In below code:

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

I am working with iOS9. I need to remove all these warnings. Thanks in advance!

like image 560
user5513630 Avatar asked Nov 04 '15 15:11

user5513630


1 Answers

appearanceWhenContainedInInstancesOfClasses: wants an NSArray of classes. Thus:

[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:[UIColor whiteColor]];

Instead of base64Encoding (which has been deprecated since iOS 7.0 so that's not a new warning for you), use this:

NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:0]];

Regarding searchDisplayController, see this Q&A.

Regarding sendSynchronousRequest:returningResponse:error:, the error message is clear. You need to rewrite that part of your app to use an NSURLSession and its dataTaskWithRequest:completionHandler: method. There are lots of helpful resources for this on the Internet, like this objc.io article: “From NSURLConnection to NSURLSession”.

like image 158
rob mayoff Avatar answered Sep 30 '22 18:09

rob mayoff