diff --git a/SwiftRadio/Info.plist b/SwiftRadio/Info.plist
index 13bcea89..286279f1 100755
--- a/SwiftRadio/Info.plist
+++ b/SwiftRadio/Info.plist
@@ -29,6 +29,10 @@
NSAllowsArbitraryLoads
+ NSUserActivityTypes
+
+ NSUserActivityTypeBrowsingWeb
+
UIBackgroundModes
audio
diff --git a/SwiftRadio/NowPlayingViewController.swift b/SwiftRadio/NowPlayingViewController.swift
index 322f2367..ca2486e9 100755
--- a/SwiftRadio/NowPlayingViewController.swift
+++ b/SwiftRadio/NowPlayingViewController.swift
@@ -55,6 +55,9 @@ class NowPlayingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
+ // Setup handoff functionality - GH
+ setupUserActivity()
+
// Set AlbumArtwork Constraints
optimizeForDeviceSize()
@@ -534,6 +537,7 @@ class NowPlayingViewController: UIViewController {
// Update Labels
self.artistLabel.text = self.track.artist
self.songLabel.text = self.track.title
+ self.updateUserActivityState(self.userActivity!)
// songLabel animation
self.songLabel.animation = "zoomIn"
@@ -553,4 +557,26 @@ class NowPlayingViewController: UIViewController {
}
}
}
+
+ //*****************************************************************
+ // MARK: - Handoff Functionality - GH
+ //*****************************************************************
+
+ func setupUserActivity() {
+ let activity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb ) //"com.graemeharrison.handoff.googlesearch" //NSUserActivityTypeBrowsingWeb
+ userActivity = activity
+ let url = "https://www.google.com/search?q=\(self.artistLabel.text!)+\(self.songLabel.text!)"
+ let urlStr = url.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
+ let searchURL : NSURL = NSURL(string: urlStr!)!
+ activity.webpageURL = searchURL
+ userActivity?.becomeCurrent()
+ }
+
+ override func updateUserActivityState(activity: NSUserActivity) {
+ let url = "https://www.google.com/search?q=\(self.artistLabel.text!)+\(self.songLabel.text!)"
+ let urlStr = url.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
+ let searchURL : NSURL = NSURL(string: urlStr!)!
+ activity.webpageURL = searchURL
+ super.updateUserActivityState(activity)
+ }
}