為迎合項目需求,在個人推廣二維碼的時候添加長按保存圖片到相冊的功能.但是,往往有部分用戶在使用的時候會拒絕程序訪問照片,導(dǎo)致后期保存圖片失敗...好了,既然有這一需求,那就有相應(yīng)實現(xiàn).首先找到Info.plist,在URL types下添加相應(yīng)的URL Schemes,如下圖所示:
實現(xiàn)方法如下,可以直接復(fù)制,復(fù)制前請先引入系統(tǒng)庫#import <AssetsLibrary/AssetsLibrary.h>
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
{
if (error){
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//無訪問權(quán)限
CustomAlertController *alert = [CustomAlertController alertControllerWithTitle:@"提示" message:@"保存失敗!請在設(shè)備的“設(shè)置-隱私-照片”中允許程序訪問你的照片硼一。" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:^{
alert.OKAction = ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=PHOTOS"]];
};
}];
}else{
[MBProgressHUD showMessage:error.localizedRecoverySuggestion view:self.view];
}
}else {
[MBProgressHUD showSuccess:@"保存成功" toView:self.view];
}
}
跳轉(zhuǎn)設(shè)置的字段
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
AirplaneModeOn— prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date& Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General— prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE? iCloud
Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music VolumeLimit— prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari? Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
SoftwareUpdate— prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter —?prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
Setting—prefs:root=INTERNET_TETHERING
注:
系統(tǒng)版本 >= 10.0時
NSURL*url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];