試圖強制Handoff功能在iOS 9設備上使用iPhone 5和iPad Air,並且遇到與iOS9相關的問題 - 無法在iOS 8上查看,因爲我沒有設備這個系統。Handoff不適用於iOS 9設備
問題:
- 我第一次打開設備上的應用程序時,在創建用戶活動
- 在我的鎖屏幕上看到的第二設備主屏幕,有與我的應用程序 一些活動
- 我正在打開此應用程序,
application:continueUserActivity:restorationHandler:
未在此設備上調用,因此我無法向用戶顯示第一臺設備上顯示的內容。
您可以在github上瀏覽整個項目:https://github.com/tomkowz/Quotes
實現細節:
我已經更新目標的plist文件,並添加NSUserActivityTypes
。
<key>NSUserActivityTypes</key>
<array>
<string>com.tomaszszulc.Quotes.quotesList</string>
<string>com.tomaszszulc.Quotes.browseQuote</string>
</array>
接下來,我已經創建枚舉這些聲明類型:
enum ActivityType: String {
case BrowseQuote = "com.tomaszszulc.Quotes.browseQuote"
case QuotesList = "com.tomaszszulc.Quotes.quotesList"
}
當用戶是我開始NSUserActivity
在主屏幕上。
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
quotes = Quote.findAll(CoreDataStack.sharedInstance().mainContext)
tableView.reloadData()
startUserActivity()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
userActivity?.invalidate()
}
func startUserActivity() {
let activity = NSUserActivity(activityType: ActivityType.QuotesList.rawValue)
activity.title = "Viewing Quotes List"
userActivity = activity
userActivity?.becomeCurrent()
}
當用戶轉到所選項目的詳細信息時,將激活第二種活動。這裏是意見流量:
UINavigationController -> (root) QuotesListViewController -> (push) QuoteDetailsViewController
下面是代碼爲QuoteDetailsViewController
創建用戶活動:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
userActivity = viewModel.userActivity // (viewModel) quote.userActivity
userActivity?.becomeCurrent()
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
userActivity?.invalidate()
}
而且viewModel.userActivity
電話:
extension Quote {
@available(iOS 8.0, *)
var userActivity: NSUserActivity {
let activity = NSUserActivity(activityType: ActivityType.BrowseQuote.rawValue)
activity.title = "Reading " + self.author + " quote"
activity.userInfo = [QuoteUserActivityKey.Identifier.rawValue: self.identifier]
// Core Spotlight support
if #available(iOS 9.0, *) {
activity.contentAttributeSet = self.searchableItemAttributeSet()
activity.keywords = Set([self.author])
activity.eligibleForSearch = true
activity.eligibleForHandoff = true
}
return activity
}
}
預先感謝您!
我已經提交了一個錯誤:http://www.openradar.me/radar?id=5534110390943744 –