注:此教程來源於http://www.raywenderlich.com的《iOS8 by Tutorials》
git
1 //1.調用openURL(),它是UIApplication的一個方法,然而,在擴展中並無UIApplication對象,Apple提供了新的接口:在NSExtensionContext中有下面的方法: 2 - (void)openURL:(NSURL *)URL completionHandler:(void (^)(BOOL success))completionHandler 3 //2.創建一個shared data container:使用NSUserDefaults存取數據、直接創建一個文件負責數據存取
在iOS8中開發者能夠在通知欄中定製本身App的今日界面顯示,以下圖:github
1 //在最後說明下NCWidgetProviding中的幾個方法 2 //下面的方法是今日擴展的刷新設置 3 - (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult result))completionHandler { 4 // If an error is encountered, use NCUpdateResultFailed 5 // If there's no update required, use NCUpdateResultNoData 6 // If there's an update, use NCUpdateResultNewData 7 [self updateWithCurrencyData]; 8 completionHandler(NCUpdateResultNewData); 9 } 10 //下面的方法設置界面左側的偏移量 11 - (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets { 12 return UIEdgeInsetsZero;//使左側默認留白區域被填充 13 } 14 //下面的方法用於實現vibrancy特效 15 + (UIVibrancyEffect *)notificationCenterVibrancyEffect;
實現源碼:源代碼點擊網絡