我正在製作一個包含今日延伸的應用程序。今天的擴展顯示了一個定時器列表,如果用戶選擇了其中一個定時器,我想爲該定時器創建並安排一個本地通知。從今日延長內安排本地通知
我的問題是,通知的調度與這行代碼來完成:
UIApplication.sharedApplication().scheduleLocalNotification(notification)
這非常可惜的是依賴於UIApplication.sharedApplication()
不是從一個擴展訪問。
所以我的問題是:我該如何安排一個本地通知來自今天的延長?
有趣的是,我可以在我的應用程序和我的分機之間,並在該框架內共享代碼的框架,我可以打電話:
func schedule() {
// ...
let settings = UIUserNotificationSettings(forTypes: .Sound | .Alert, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
// ...
UIApplication.sharedApplication().scheduleLocalNotification(notification)
// ...
}
如果我再從我的分機導入框架,並呼籲schedule()
我得到這樣的輸出:
Failed to inherit CoreMedia permissions from 13636: (null)
Attempting to schedule a local notification <UIConcreteLocalNotification: 0x7feaf3657a00>{fire date = Saturday, November 1, 2014 at 1:01:48 PM Western European Standard Time, time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Saturday, November 1, 2014 at 1:01:48 PM Western European Standard Time, user info = (null)} with an alert but haven't received permission from the user to display alerts
Attempting to schedule a local notification <UIConcreteLocalNotification: 0x7feaf3657a00>{fire date = Saturday, November 1, 2014 at 1:01:48 PM Western European Standard Time, time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Saturday, November 1, 2014 at 1:01:48 PM Western European Standard Time, user info = (null)} with a sound but haven't received permission from the user to play sounds
所以在擴展運行的模塊訪問UIApplication.sharedApplication()
因爲這段代碼實際上嘗試安排的通知,但系統沒有爲EXTENS準備離子要求顯示警報的權限,所以它失敗(這就是它似乎無論如何)。
我該如何解決這個問題?
此外,我知道我可以啓動我的應用程序使用一個URL並安排來自應用程序的通知正常,但這是而不是用戶firendly。擁有今天擴展的全部目的是讓用戶不必打開應用程序來安排通知。交互必須是快速,簡單和透明的,並將用戶從他們所在的應用程序中拖出來,只需運行幾行代碼,然後完成它就不是我想要做的事情。
嗨,您有任何信息表明Apple修復了嗎? – 2015-04-05 10:33:15
@RomanBarzyczak沒有什麼解決。這是蘋果做的目的... – orenk86 2015-04-22 07:21:37
@ orenk86好,謝謝,也許你有任何想法如何從擴展調度本地通知? – 2015-04-22 18:31:42