Skip to content

Commit 0b6fe11

Browse files
author
Steve Trease
committed
Readded display of MessageID from push message the and timestamp sent included in the push message rather than the time received.
1 parent 2dbd26f commit 0b6fe11

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

Swift Push 3/AppDelegate.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import UIKit
1010
import CoreData
1111

12+
1213
@UIApplicationMain
1314
class AppDelegate: UIResponder, UIApplicationDelegate {
1415

@@ -62,6 +63,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6263
NSUserDefaults.standardUserDefaults().synchronize()
6364

6465
let receipt = NSBundle.mainBundle().appStoreReceiptURL?.lastPathComponent
66+
let mode = receipt
6567
let versionNumber: AnyObject? = NSBundle.mainBundle().infoDictionary?["CFBundleVersion"]
6668

6769
// register device token with push service
@@ -70,7 +72,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7072
request.HTTPMethod = "POST"
7173
var bodyData = "token=\(deviceToken.description)"
7274
bodyData += "&device=\(UIDevice.currentDevice().name)"
73-
bodyData += "&mode=\(receipt!)"
75+
bodyData += "&mode=\(mode!)"
7476
bodyData += "&version=\(versionNumber!)"
7577
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)
7678
var connection = NSURLConnection(request: request, delegate: self, startImmediately: false)
@@ -101,16 +103,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
101103
if let aps = userInfo["aps"] as? NSDictionary {
102104
if let alert = aps["alert"] as? String {
103105
item.alert = alert
106+
println ("alert: \(alert)")
104107
}
105108
}
106-
107-
// var payload = userInfo.objectForKey("payload") as String
108-
// var timeStamp = userInfo.objectForKey("timestamp") as String
109-
// var messageID = userInfo.objectForKey("messageID") as Int
110-
111-
// item.payload = alert
112-
// item.timeStamp = NSDate()
113-
// item.messageID = messageID
109+
if let messageID = userInfo["messageID"] as? Int {
110+
item.messageID = messageID
111+
println ("messageID: \(messageID)")
112+
}
113+
if let timeStamp = userInfo["timestamp"] as? NSTimeInterval {
114+
item.timeStamp = NSDate (timeIntervalSince1970: timeStamp)
115+
println ("timestamp: \(timeStamp)")
116+
}
114117

115118
notifications.insert(item, atIndex: 0)
116119
if (notifications.count > maxNotifications) {

Swift Push 3/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>295</string>
22+
<string>318</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UIBackgroundModes</key>

Swift Push 3/NotificationData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class NotificationData {
1616
var alert: String = ""
1717
// 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ class NotificationsTableViewController: UITableViewController, UISearchBarDelega
9393
cell.detailTextLabel?.numberOfLines = 0
9494

9595
cell.textLabel?.text = notification.alert as String
96-
cell.detailTextLabel?.text = NSDateFormatter.localizedStringFromDate(notification.timeStamp, dateStyle: .MediumStyle, timeStyle: .ShortStyle)
96+
// var detailTextLabel: String = NSDateFormatter.localizedStringFromDate(notification.timeStamp, dateStyle: .MediumStyle, timeStyle: .ShortStyle) as String
97+
// etailTextLabel += " \(notification.messageID) "
98+
// ell.detailTextLabel?.text = detailTextLabel
99+
cell.detailTextLabel?.text = NSDateFormatter.localizedStringFromDate(notification.timeStamp, dateStyle: .MediumStyle, timeStyle: .ShortStyle) as String + " (\(notification.messageID))"
100+
97101

98102
if (indexPath.row % 2 == 0 ) {
99103
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>295</string>
9+
<string>318</string>
1010
<key>Key</key>
1111
<string>CurrentBuildNumber</string>
1212
<key>Title</key>

0 commit comments

Comments
 (0)