Skip to content

Commit b631b86

Browse files
committed
Strip <> and whitespace from device tokens before posting
1 parent c6d16a4 commit b631b86

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Swift Push/AppDelegate.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7373

7474

7575
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken:Data) {
76-
// let existingToken: AnyObject? = NSUserDefaults.standardUserDefaults().objectForKey("deviceToken")
76+
var token: String = deviceToken.description
77+
token = token.replacingOccurrences(of: "[^0-9 ]", with: "")
7778

78-
print("device token is " + deviceToken.description)
79-
UserDefaults.standard().set(deviceToken.description as String, forKey:"deviceToken")
79+
print("device token is \(token)")
80+
UserDefaults.standard().set(token as String, forKey:"deviceToken")
8081
UserDefaults.standard().synchronize()
8182

82-
newRecord("Device token is \(deviceToken.description)", alert: false, messageID: 0)
83+
newRecord("Device token is \(token)", alert: false, messageID: 0)
8384

8485
let receipt = Bundle.main().appStoreReceiptURL?.lastPathComponent
8586
let mode = receipt
8687
let versionNumber: AnyObject? = Bundle.main().infoDictionary?["CFBundleVersion"]
8788

8889
var request = URLRequest(url: URL(string: "https://www.trease.eu/ibeacon/swiftpush/")!)
8990
request.httpMethod = "POST"
90-
var bodyData = "token=\(deviceToken.description)"
91+
var bodyData = "token=\(token)"
9192
bodyData += "&device=\(UIDevice.current().name)"
9293
bodyData += "&mode=\(mode!)"
9394
bodyData += "&version=\(versionNumber!)"

Swift Push/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>445</string>
22+
<string>448</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UIBackgroundModes</key>

Swift Push/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-
<integer>445</integer>
9+
<integer>448</integer>
1010
<key>Key</key>
1111
<string>maximumRecords</string>
1212
<key>MaximumValue</key>

0 commit comments

Comments
 (0)