Skip to content

Commit

Permalink
Merge handoff from Graeme Harrison
Browse files Browse the repository at this point in the history
Thanks to GH for adding handoff functionality
  • Loading branch information
analogcode committed Mar 27, 2016
1 parent 9cd071e commit 444e059
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions SwiftRadio/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>NSUserActivityTypeBrowsingWeb</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
Expand Down
26 changes: 26 additions & 0 deletions SwiftRadio/NowPlayingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class NowPlayingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

// Setup handoff functionality - GH
setupUserActivity()

// Set AlbumArtwork Constraints
optimizeForDeviceSize()

Expand Down Expand Up @@ -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"
Expand All @@ -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)
}
}

0 comments on commit 444e059

Please sign in to comment.