From 3994f4e8cf21afed18e6ebae37e0ab7e1b91a30e Mon Sep 17 00:00:00 2001 From: Kilian Koeltzsch Date: Thu, 9 Jul 2015 10:12:11 +0200 Subject: [PATCH] Update all 5 minutes and read an RSS feed updating via a timer every five minutes (still loving SwiftyTimer) and using MWFeedParser to read the RSS feed at parkendd.tumblr.com. This'll be used to display updates to the user should anything change or be sent out. See #76 --- ParkenDD/Constants.swift | 1 + ParkenDD/LotlistViewController.swift | 31 ++++++++++++++++++++++++++-- Podfile | 2 ++ Podfile.lock | 14 +++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/ParkenDD/Constants.swift b/ParkenDD/Constants.swift index bad5bf2..2006b1d 100644 --- a/ParkenDD/Constants.swift +++ b/ParkenDD/Constants.swift @@ -12,4 +12,5 @@ struct Const { static let apibaseURL = "https://park-api.higgsboson.tk/" static let supportedAPIVersion = 1.0 + static let rssURL = "http://parkendd.tumblr.com/rss" } diff --git a/ParkenDD/LotlistViewController.swift b/ParkenDD/LotlistViewController.swift index 9dfb404..ef19431 100644 --- a/ParkenDD/LotlistViewController.swift +++ b/ParkenDD/LotlistViewController.swift @@ -10,9 +10,11 @@ import UIKit import CoreLocation //import MCSwipeTableViewCell import TSMessages +import SwiftyTimer +import MWFeedParser // Removing MCSwipeTableViewCellDelegate here temporarily -class LotlistViewController: UITableViewController, CLLocationManagerDelegate, UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating { +class LotlistViewController: UITableViewController, CLLocationManagerDelegate, UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating, MWFeedParserDelegate { let locationManager = CLLocationManager() @@ -26,6 +28,8 @@ class LotlistViewController: UITableViewController, CLLocationManagerDelegate, U var timeDownloaded: NSDate? var dataSource: String? + var feedItems = [MWFeedItem]() + override func viewDidLoad() { super.viewDidLoad() @@ -62,7 +66,15 @@ class LotlistViewController: UITableViewController, CLLocationManagerDelegate, U // Set a table footer view so that separators aren't shown when no data is yet present self.tableView.tableFooterView = UIView(frame: CGRectZero) + // Create Feed Parser for news notification + let rssURL = NSURL(string: Const.rssURL) + let feedParser = MWFeedParser(feedURL: rssURL) + feedParser.delegate = self + feedParser.connectionType = ConnectionTypeAsynchronously + feedParser.parse() + updateData() + NSTimer.every(5.minutes,updateData) } override func viewWillAppear(animated: Bool) { @@ -487,7 +499,6 @@ class LotlistViewController: UITableViewController, CLLocationManagerDelegate, U // ///////////////////////////////////////////////////////////////////////// // MARK: - CLLocationManagerDelegate // ///////////////////////////////////////////////////////////////////////// - func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { let currentLocation: CLLocation = locations.last as! CLLocation @@ -559,4 +570,20 @@ class LotlistViewController: UITableViewController, CLLocationManagerDelegate, U return imageView } + // ///////////////////////////////////////////////////////////////////////// + // MARK: - MWFeedParser + // ///////////////////////////////////////////////////////////////////////// + + func feedParser(parser: MWFeedParser!, didParseFeedItem item: MWFeedItem!) { + self.feedItems.append(item) + } + + func feedParserDidFinish(parser: MWFeedParser!) { + let lastItem = self.feedItems.first + let request = NSURLRequest(URL: NSURL(string: lastItem!.link)!) + + // TODO: Display a modal VC with the post page of the latest post + // Some kind of check for which notifications have been displayed needs to be built as well + } + } diff --git a/Podfile b/Podfile index 05f4b02..92ebd7f 100644 --- a/Podfile +++ b/Podfile @@ -8,3 +8,5 @@ pod 'BEMSimpleLineGraph', '~> 3.3' pod 'MCSwipeTableViewCell', '~> 2.1.2' pod 'Alamofire', '~> 1.2' pod 'SwiftyJSON', '~> 2.2' +pod 'SwiftyTimer', '~> 1.1.0' +pod 'MWFeedParser', '~> 1.0.1' diff --git a/Podfile.lock b/Podfile.lock index 2b847ea..d39da8d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -3,7 +3,17 @@ PODS: - BEMSimpleLineGraph (3.3) - HexColors (2.2.1) - MCSwipeTableViewCell (2.1.2) + - MWFeedParser (1.0.1): + - MWFeedParser/FeedParser (= 1.0.1) + - MWFeedParser/NSDate+InternetDateTime (= 1.0.1) + - MWFeedParser/NSString+HTML (= 1.0.1) + - MWFeedParser/FeedParser (1.0.1): + - MWFeedParser/NSDate+InternetDateTime + - MWFeedParser/NSString+HTML + - MWFeedParser/NSDate+InternetDateTime (1.0.1) + - MWFeedParser/NSString+HTML (1.0.1) - SwiftyJSON (2.2.0) + - SwiftyTimer (1.1.0) - TSMessages (0.9.12): - HexColors @@ -11,7 +21,9 @@ DEPENDENCIES: - Alamofire (~> 1.2) - BEMSimpleLineGraph (~> 3.3) - MCSwipeTableViewCell (~> 2.1.2) + - MWFeedParser (~> 1.0.1) - SwiftyJSON (~> 2.2) + - SwiftyTimer (~> 1.1.0) - TSMessages (~> 0.9.12) SPEC CHECKSUMS: @@ -19,7 +31,9 @@ SPEC CHECKSUMS: BEMSimpleLineGraph: 7fc92cd65a5f91640f6624b11be96fe1f3d7f1cf HexColors: abfd172e329dab59888614ccba6f216cec59289d MCSwipeTableViewCell: 0fc22bd3635b9b5f4ce08675218b0a7278b6440f + MWFeedParser: 2cf646014c1baf6ad1b08c480b40a08180079247 SwiftyJSON: 0b3e6c07af17ff745e77e8e9984097b55c956e5c + SwiftyTimer: 3b1bf42c8b1bb09dff7107b12d3b73cbf700bbce TSMessages: 2a52642128d7ab15b46930c810b9c9403a2b58f3 COCOAPODS: 0.37.2