Skip to content

Commit f7f3ae6

Browse files
author
Steve Trease
committed
Simplification
1 parent 532a21f commit f7f3ae6

File tree

5 files changed

+21
-52
lines changed

5 files changed

+21
-52
lines changed

Swift Push 3/AppDelegate.swift

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1717
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1818
// Override point for customization after application launch.
1919

20-
var versionNumber: AnyObject = NSBundle.mainBundle().infoDictionary!["CFBundleVersion"]!
21-
println ("version \(versionNumber)")
20+
// var versionNumber: AnyObject = NSBundle.mainBundle().infoDictionary["CFBundleVersion"]
21+
// println ("version \(versionNumber)")
2222

2323
var item = NotificationData()
24-
item.alert = "Swift Push (\(versionNumber)) starting on " + UIDevice.currentDevice().name
24+
// item.alert = "Swift Push (\(versionNumber)) starting on " + UIDevice.currentDevice().name
25+
item.alert = "Swift Push starting on " + UIDevice.currentDevice().name
2526

2627
notifications.insert(item, atIndex: 0)
2728

@@ -102,37 +103,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
102103
// decode mesage and create new object
103104
var t1: AnyObject! = userInfo.objectForKey("aps")
104105
var alert = t1.objectForKey("alert") as String
105-
var payload = userInfo.objectForKey("payload") as String
106+
// var payload = userInfo.objectForKey("payload") as String
106107
// var timeStamp = userInfo.objectForKey("timestamp") as String
107-
var messageID = userInfo.objectForKey("messageID") as Int
108+
// var messageID = userInfo.objectForKey("messageID") as Int
108109

109110
var item = NotificationData()
110111
item.alert = alert
111-
item.payload = payload
112-
// item.timeStamp = NSDate(timeIntervalSince1970: timeStamp)
113-
item.messageID = messageID
114-
115-
116-
// Is this a new message? Check for exisitance of messageID in array
117-
var newItem = true;
118-
for n in notifications {
119-
if (n.messageID == item.messageID) {
120-
newItem = false
121-
}
122-
}
112+
// item.payload = alert
113+
// item.timeStamp = NSDate()
114+
// item.messageID = messageID
123115

124-
if (newItem == true) {
125-
println("adding notification")
126-
notifications.insert(item, atIndex: 0)
127-
if (notifications.count > maxNotifications) {
128-
notifications.removeLast()
129-
}
130-
// notify tableview to refresh
131-
let center = NSNotificationCenter.defaultCenter()
132-
center.postNotificationName("dataChanged", object: self)
133-
} else {
134-
println("duplicate notification - ignoring")
116+
notifications.insert(item, atIndex: 0)
117+
if (notifications.count > maxNotifications) {
118+
notifications.removeLast()
135119
}
120+
let center = NSNotificationCenter.defaultCenter()
121+
center.postNotificationName("dataChanged", object: self)
136122

137123
// finished
138124
completionHandler(UIBackgroundFetchResult.NewData)

Swift Push 3/NotificationData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let maxNotifications = 64
1414

1515
class NotificationData {
1616
var alert: String = ""
17-
var payload: String = ""
17+
// var payload: String = ""
1818
var timeStamp = NSDate() // timestamp the date/time the notification record is created
19-
var messageID: Int = 0
19+
// var messageID: Int = 0
2020
}

Swift Push 3/NotificationsTableViewController.swift

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,15 @@ class NotificationsTableViewController: UITableViewController {
6767
// println("cellForRowAtIndexPath")
6868
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "ReuseCell")
6969

70-
// cell.layer.cornerRadius = 5.0
71-
// cell.layer.masksToBounds = true
72-
73-
70+
cell.layer.cornerRadius = 5.0
71+
cell.layer.masksToBounds = true
7472
cell.textLabel?.numberOfLines = 0
7573
cell.detailTextLabel?.numberOfLines = 0
7674

77-
var timeStamp = NSDateFormatter.localizedStringFromDate(notifications[indexPath.row].timeStamp, dateStyle: .MediumStyle, timeStyle: .ShortStyle)
75+
let timeStamp = NSDateFormatter.localizedStringFromDate(notifications[indexPath.row].timeStamp, dateStyle: .MediumStyle, timeStyle: .ShortStyle)
7876

7977
cell.textLabel?.text = notifications[indexPath.row].alert as String
80-
81-
var detailString: String = ""
82-
// is there a message payload?
83-
if (notifications[indexPath.row].payload != "" ) {
84-
detailString =
85-
notifications[indexPath.row].payload
86-
+ "\n"
87-
}
88-
detailString = detailString + timeStamp
89-
if (notifications[indexPath.row].messageID > 0) {
90-
detailString = detailString
91-
+ " ("
92-
+ String(notifications[indexPath.row].messageID)
93-
+ ")"
94-
}
95-
cell.detailTextLabel?.text = detailString
78+
cell.detailTextLabel?.text = timeStamp
9679

9780
if (indexPath.row % 2 == 0 ) {
9881
cell.backgroundColor = UIColor(white: 0.95, alpha: 1.0)

Swift Push 3/Settings.bundle/Root.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<array>
77
<dict>
88
<key>DefaultValue</key>
9-
<string>196</string>
9+
<string>210</string>
1010
<key>Key</key>
1111
<string>CurrentBuildNumber</string>
1212
<key>Title</key>

0 commit comments

Comments
 (0)