Use of a deprecated Cocoa or UIKit API
ID |
objectivec.portability.deprecated_api |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Deprecated Api |
Language |
Objective-C |
Description
Reports a use of a Cocoa, UIKit or Core Telephony API that Apple has formally deprecated, together with the release that deprecated it and the API that replaces it.
Rationale
A deprecated API is frozen: it receives no fixes, no new behaviour and no support for capabilities added after its deprecation, and Apple removes such APIs outright once the transition period ends - UIWebView already blocks App Store submission. Several of these in particular are actively harmful while they still work. UIWebView runs JavaScript in the app’s own process with no per-frame isolation; NSURLConnection sendSynchronousRequest: blocks the calling thread for the whole request; NSKeyedUnarchiver unarchiveObjectWithData: decodes without a class allowlist, so a tampered archive can instantiate arbitrary classes; and stringByAddingPercentEscapesUsingEncoding: escapes the wrong character set for a URL component.
The following code illustrates the pattern detected by this rule:
@implementation LegacyScreen
- (void)showWebContent:(NSURL *)url inView:(UIView *)container {
// FLAGGED: Use of a deprecated Cocoa or UIKit API
UIWebView *web = [[UIWebView alloc] initWithFrame:container.bounds];
[web loadRequest:[NSURLRequest requestWithURL:url]];
[container addSubview:web];
}
@end
Remediation
Migrate each call to its documented replacement - WKWebView for UIWebView, UIAlertController for UIAlertView and UIActionSheet, NSURLSession for NSURLConnection, UNNotificationRequest for UILocalNotification, AVPlayerViewController for MPMoviePlayerController, the Photos framework for ALAssetsLibrary, CallKit for CTCallCenter, stringByAddingPercentEncodingWithAllowedCharacters: and stringByRemovingPercentEncoding for the percent-escape methods, unarchivedObjectOfClass:fromData:error: for the NSKeyedUnarchiver object convenience methods, the view controller’s prefersStatusBarHidden/preferredStatusBarStyle for the UIApplication status bar setters, AVAudioSession for the AudioSession C functions, and UIGraphicsImageRenderer for UIGraphicsBeginImageContext.