-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
executable file
·190 lines (110 loc) · 7.16 KB
/
Copy pathAppDelegate.swift
File metadata and controls
executable file
·190 lines (110 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// AppDelegate.swift
// B1Summit2016
//
// Created by SAP on 9/30/15.
// Copyright © 2016 Speidel, Duncan. All rights reserved.
// Watch version
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var vc = ViewController.self
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let types: UIUserNotificationType = UIUserNotificationType.Badge
let settings: UIUserNotificationSettings = UIUserNotificationSettings( forTypes: types, categories: nil )
application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData )
{
let characterSet: NSCharacterSet = NSCharacterSet( charactersInString: "<>" )
let deviceTokenString: String = ( deviceToken.description as NSString )
.stringByTrimmingCharactersInSet( characterSet )
.stringByReplacingOccurrencesOfString( " ", withString: "" ) as String
MyDraft.deviceToken = deviceTokenString
print( deviceTokenString )
//self.RegisterPhone()
/*
* Tried to do the steps below in a separate function but couldn't find a way to extend class appDelegate, will revisit this in the future
* when I have more time
*/
//Register Phone with HANA
//https://54.191.40.200:4300/B1APN/B1APN.xsjs?token=4b3230c2c417611326d7f3211b5c415de76f810d44899983c05007ec93ee1bed
var B1APNXSJS = NSURL()
//Switching to plain text to avoid issues with self signed certificate
MyDraft.deviceToken = MyDraft.deviceToken.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
B1APNXSJS = NSURL(string: "http://54.191.40.200:8000/B1APN/B1APN.xsjs?token=\(MyDraft.deviceToken)")!
let xsjsRequest:NSMutableURLRequest = NSMutableURLRequest(URL:B1APNXSJS)
let task = NSURLSession.sharedSession().dataTaskWithRequest(xsjsRequest) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
}
task.resume()
}//didRegisterForRemoteNotifications
func application( application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError ) {
print( error.localizedDescription )
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler:(UIBackgroundFetchResult) -> Void)
{
/*
* Used to unbundle the NSDictonary object that we receive from APN
*/
if let aps = userInfo["aps"] as? NSDictionary {
if let alert = aps["alert"] as? NSDictionary {
if let message = alert["message"] as? NSString {
//Do stuff
var draftNum = alert.description
draftNum = draftNum.stringByReplacingOccurrencesOfString("New approval request for sales order draft", withString: "")
MyDraft.draft=draftNum.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
}
} else if let alert = aps["alert"] as? NSString {
let draftNum = alert.stringByReplacingOccurrencesOfString("New approval request for sales order draft", withString: "")
MyDraft.draft=draftNum.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
}
}
completionHandler (.NoData) //Need this to close handler or iOS complains
}//End didReceiveRemoteNotification
//func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData )
//func application (application: UIApplication, RegiserPhone)
//class AppDelegate{
func RegiserPhone()
{
//https://54.191.40.200:4300/B1APN/B1APN.xsjs?token=4b3230c2c417611326d7f3211b5c415de76f810d44899983c05007ec93ee1bed
var B1APNXSJS = NSURL()
B1APNXSJS = NSURL(string: "https://54.191.40.200:4300/B1APN/B1APN.xsjs?token=\(MyDraft.deviceToken)")!
let xsjsRequest:NSMutableURLRequest = NSMutableURLRequest(URL:B1APNXSJS)
let task = NSURLSession.sharedSession().dataTaskWithRequest(xsjsRequest) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
//let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
}
task.resume()
}//close RegisterPhone
}//Close class