2016-09-30 59 views
3

我目前有一個問題,UILocalNotifications中的自定義聲音只在第一次安裝應用程序時起作用。在第二次安裝應用程序(即模擬升級)之後,聲音會回到默認聲音,即使是新創建的通知。我創建了一個新的測試項目來測試最低限度的問題和仍然存在的問題。下面是我的ViewController:UILocalNotification自定義聲音在更新應用程序後不工作

class ViewController: UIViewController { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    let notification = createNotification() 
    UIApplication.shared.scheduleLocalNotification(notification) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func createNotification() -> UILocalNotification { 
    let tenSecondsLater = Date().addingTimeInterval(10) 

    let notification = UILocalNotification() 
    notification.fireDate = tenSecondsLater 
    notification.alertTitle = "Test Notification Title" 
    notification.alertBody = "body" 
    notification.soundName = "alarm-20secs.wav" 

    return notification 
} 

}

權限中正確設置的AppDelegate:

UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound], categories: nil)) 

再現步驟:

  1. 在Xcode中壓運行安裝程序。按回家的背景應用程序
  2. 〜10秒鐘後,警報顯示正常播放的聲音正常
  3. 再次按下Xcode中的Run,再次安裝應用程序。按回家後臺應用程序
  4. 〜10秒鐘後,警報顯示,但現在默認播放聲音。

我已經嘗試調用cancelAllLocalNotifications(),但它似乎沒有改變任何東西。強制殺死不會重現問題,只會升級。升級後,聲音仍然可以使用AVPlayer播放,所以不會像文件被刪除;只有本地通知受到影響。

我很清楚UILocalNotification在iOS 10中已被棄用,但新的UserNotification框架不支持重複通知,這是我需要的功能。這個問題發生在運行iOS 10和10.0.2的sim和設備上。我找不到任何其他線索來描述這個特殊問題,對於大多數人來說,他們根本聽不到他們的聲音。在這種情況下,它工作正常,但只有在重新安裝應用程序後。當我發佈新版本時,這會是一個問題,因爲升級路徑會破壞通知聲音,這對我的應用程序至關重要。

回答

2

也許現在,大家都知道,這是由10 IOS的​​錯誤引起的..

手機重新啓動(應用程序更新後)也將修復它。

+0

你碰巧在這個ios10問題上有參考/鏈接到雷達? – ccwasden

+0

刪除應用程序並重新安裝它爲我完成了這項工作。 –