@@ -56,7 +56,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5656 }
5757
5858
59- func application( application: UIApplication ! , didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData ! ) {
59+ func application( application: UIApplication , didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData ) {
6060 let existingToken : AnyObject ? = NSUserDefaults . standardUserDefaults ( ) . objectForKey ( " deviceToken " )
6161
6262 println ( " device token is " + deviceToken. description)
@@ -66,7 +66,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6666 var receipt = NSBundle . mainBundle ( ) . appStoreReceiptURL? . lastPathComponent
6767
6868 // register device token with push service
69- var request = NSMutableURLRequest ( URL: NSURL ( string: " https ://www.trease.eu/ibeacon/swiftpush/" ) !)
69+ var request = NSMutableURLRequest ( URL: NSURL ( string: " http ://www.trease.eu/ibeacon/swiftpush/" ) !)
7070 var session = NSURLSession . sharedSession ( )
7171 request. HTTPMethod = " POST "
7272 var bodyData = " token= " + deviceToken. description
@@ -78,13 +78,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7878 }
7979
8080
81- func application( application: UIApplication ! , didFailToRegisterForRemoteNotificationsWithError error: NSError ! ) {
81+ func application( application: UIApplication , didFailToRegisterForRemoteNotificationsWithError error: NSError ) {
8282 println ( " Failed to register device token " )
8383 println ( error. localizedDescription )
8484 }
8585
86-
87- func application( application: UIApplication ! , didReceiveRemoteNotification userInfo: NSDictionary ! , fetchCompletionHandler completionHandler: ( ( UIBackgroundFetchResult ) -> Void ) ! ) {
86+ func application( application: UIApplication , didReceiveRemoteNotification userInfo: [ NSObject : AnyObject ] , fetchCompletionHandler completionHandler: ( UIBackgroundFetchResult ) -> Void ) {
8887 switch ( application. applicationState) {
8988 case UIApplicationState . Active:
9089 println ( " notification received by AppDeligate whilst active " )
@@ -97,15 +96,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
9796 }
9897 println ( userInfo)
9998
100- // decode mesage and create new object
101- var t1 : AnyObject ! = userInfo. objectForKey ( " aps " )
102- var alert = t1. objectForKey ( " alert " ) as String
99+ var item = NotificationData ( )
100+
101+ if let aps = userInfo [ " aps " ] as? NSDictionary {
102+ if let alert = aps [ " alert " ] as? String {
103+ item. alert = alert
104+ }
105+ }
106+
103107 // var payload = userInfo.objectForKey("payload") as String
104108 // var timeStamp = userInfo.objectForKey("timestamp") as String
105109 // var messageID = userInfo.objectForKey("messageID") as Int
106110
107- var item = NotificationData ( )
108- item. alert = alert
109111 // item.payload = alert
110112 // item.timeStamp = NSDate()
111113 // item.messageID = messageID
@@ -119,7 +121,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
119121
120122 // finished
121123 completionHandler ( UIBackgroundFetchResult . NewData)
122-
123124 }
124125
125126 func applicationWillResignActive( application: UIApplication ) {
@@ -151,7 +152,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
151152 lazy var applicationDocumentsDirectory : NSURL = {
152153 // The directory the application uses to store the Core Data store file. This code uses a directory named "Trease.Swift_Push_3" in the application's documents Application Support directory.
153154 let urls = NSFileManager . defaultManager ( ) . URLsForDirectory ( . DocumentDirectory, inDomains: . UserDomainMask)
154- return urls [ urls. count- 1 ] as NSURL
155+ return urls [ urls. count- 1 ] as! NSURL
155156 } ( )
156157
157158 lazy var managedObjectModel : NSManagedObjectModel = {
0 commit comments