1、新url_Scheme列表 (prefs:在iOS10 中改成了Prefs:)
電池電量 Prefs:root=BATTERY_USAGE
通用設置 Prefs:root=General
存儲空間 Prefs:root=General&path=STORAGE_ICLOUD_USAGE/DEVICE_STORAGE
蜂窩數據 Prefs:root=MOBILE_DATA_SETTINGS_ID
Wi-Fi 設置 Prefs:root=WIFI
藍牙設置 Prefs:root=Bluetooth
定位設置 Prefs:root=Privacy&path=LOCATION
輔助功能 Prefs:root=General&path=ACCESSIBILITY
關于手機 Prefs:root=General&path=About
鍵盤設置 Prefs:root=General&path=Keyboard
顯示設置 Prefs:root=DISPLAY
聲音設置 Prefs:root=Sounds
App Store 設置 Prefs:root=STORE
墻紙設置 Prefs:root=Wallpaper
打開電話 Mobilephone://
世界時鐘 Clock-worldclock://
鬧鐘 Clock-alarm://
秒表 Clock-stopwatch://
倒計時 Clock-timer://
打開相冊 Photos://
# 跳轉系統app
NSURL *url = [NSURL URLWithString:@"weixin://"];
[[UIApplication sharedApplication] openURL:url];
appstore itms-apps://
日歷 calshow://
時鐘
world clock clock-worldclock://
alarm clock-alarm://
stopwatch clock-stopwatch://
timer clock-timer://
通訊錄 contact://
applewatch itms-watch://
facetime
facetime視頻 facetime://${PHONE}
facetime確認視頻 facetime-prompt://${PHONE}
facetime音頻 facetime-audio://${PHONE}
facetime確認音頻 facetime-audio-prompt://${PHONE}
find friends findmyfriends://
find iphone fmip1://
gamecenter gamecenter://
ibooks ibooks://
iclouddrive iclouddriveapp://
itunes itms://
郵件
打開郵件app message://
寫郵件 mailto:
發送電子郵件 mailto:${EMAIL}?cc=&subject=${SUBJECT}&body=${BODY}
地圖
打開地圖app http://maps.apple.com/?q=
獲取地圖路線 http://maps.apple.com/?saddr=${SADDR}&daddr=&{DADDR}
搜索地圖 http://maps.apple.com/?q=${QUERY}&near=${NEAR}
信息
寫信息 sms://
發送信息 sms:${PHONE}
群發信息 launcher://msg?to=${PHONE}&subject=${SUBJECT}&body=${BODY}
音樂 music://
新聞 applenews://
備忘錄 mobilenotes://
電話
打開電話app mobilephone://
撥打電話 tel:${PHONE}
要求確認撥打 telprompt:${PHONE}
照片 photos-redirect://
播客 pcast://
提醒事項 x-apple-reminder://
safari x-web-search://
視頻 videos://
語音備忘錄 voicememos://
wallet shoebox://
天氣 weather://?index=0
注意,類似${PHONE}這樣的代表需要參數,可以設定具體值,
tel:${PHONE} 具體到撥打10086
tel:10086
1
2
2、openURL在iOS 10中只能打開App設置界面 (模擬器&真機)
- (void)viewDidLoad {
[super viewDidLoad];
//[NSURL URLWithString:UIApplicationOpenSettingsURLString]之前調用
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self openWiFi];
}
// 打開系統的Wi-Fi界面,當系統大于10的時候直接打開當前App的設置界面
- (void)openWiFi {
NSURL *url = [NSURL URLWithString:@"Prefs:root=WIFI"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
// 系統小于10的時候,打開Wi-Fi界面
[[UIApplication sharedApplication] openURL:url];
} else {
// 系統大于10的時候直接打開當前App的設置界面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
3.gif
3、我就要在iOS 10中打開 (真機)
方案一、MobileCoreServices.framework<
// 私用API打開系統WIFI界面
- (void)privateAPIOpenWiFi {
NSURL*url=[NSURL URLWithString:@"Prefs:root=WIFI"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:@selector(defaultWorkspace)] performSelector:@selector(openSensitiveURL:withOptions:) withObject:url withObject:nil];
}
1.gif
4、使用AppExtension之 TodayExtension (真機) >方案二 <
A、擴展與宿主App之間共享數據
有兩種方式:
1.通過NSUserDefaults
2.通過一個擴展與App都可以訪問的共享容器,來存放文件,數據(Core Data, Sqlite等都可以存放在這個共享的容器中)。
1、NSUserDefault <首次需要打開App存入數據>
共享數據(AppDelegate.m)
[[[NSUserDefaults alloc] initWithSuiteName:@"group.JSPath_Demo"] setValue:@1 forKey:@"MyNote"];
取到共享數據(TodayViewController.m)
NSNumber *numValue = [[[NSUserDefaults alloc] initWithSuiteName:@"group.JSPath_Demo"] valueForKey:@"MyNote"];
NSLog(@"--->%@",numValue);
2、數據庫存更多數據 <CoreData, Sql>
B、擴展與宿主App之間共享代碼
原理:我們需要在擴展和App之間共享代碼,也就是將所有公用的文件添加到一個framework中,這樣我們只要在擴展中引入這個framework,就可以使用其中的代碼了
創建庫framework
QQ20161213-094816@2x.png
Widget手動添加framework
QQ20161213-095108@2x.png
共享 代碼或者資源文件
QQ20161213-095359@2x.png
C、 如何從擴展中打開宿主App
擴展不是一個完整的程序,所以它并沒沒有[UIApplication sharedApplication] 這個對象。所以Apple給每個UIViewController加了一個extensionContext屬性,在我們的宿主App中,這個屬性是nil,而在擴展中,我們就可以通過下面的方法。
1、設置Scheme
QQ20161213-101055@2x.png
2、跳轉路徑
[self.extensionContext openURL:[NSURL URLWithString:@"todaywidget://home" ]completionHandler:nil];
3、可以在AppDelegate的openURL代理方法中,通過URL后面的參數不同,來打開不同的頁面(AppDelegate.m)
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
if ([url.absoluteString hasPrefix:@"todaywidget"]) {
if ([url.absoluteString hasSuffix:@"home"]) {//判斷是否是直接跳入到相應頁面
UIViewController *addVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AddVC"];
UINavigationController *rootNav = (UINavigationController*)self.window.rootViewController;
[rootNav pushViewController:addVC animated:YES];
}
}
return YES;
}