Skip to content

Commit 437935d

Browse files
committed
plist updated with push credentials
1 parent 4873589 commit 437935d

File tree

8 files changed

+78
-24
lines changed

8 files changed

+78
-24
lines changed

License.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2017 IBM Corp.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Notice.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This product includes software originally developed by IBM Corporation
2+
Copyright 2017 IBM Corp.

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
# serverless-followupapp-ios
2-
A mobile follow-up app using a serverless backend in Swift
1+
# A native iOS-Swift mobile app using a serverless backend in Swift
2+
3+
The application is a feedback app that smartly analyses the Tone of the feedback provided and appropriately acknowledges the customer through a Push Notification.
4+
5+
In this application, the user authenticates against [App ID](https://console.bluemix.net/catalog/services/AppID). App ID provides access and identification tokens. Further calls to the backend API include the access token. The backend is implemented with [Cloud Functions](https://console.bluemix.net/openwhisk). The serverless actions, exposed as Web Actions, expect the token to be sent in the request headers and verify its validity (signature and expiration date) before allowing access to the actual API. When the user submits a feedback, the feedback is stored in [Cloudant](https://console.bluemix.net/catalog/services/cloudantNoSQLDB) and later processed with Tone Analyzer. Based on the analysis result, a notification is sent back to the user with [Push Notifications](https://console.bluemix.net/catalog/services/imfpush).
6+
7+
## License
8+
9+
See [License.txt](License.txt) for license information.
10+

deploy.sh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,20 @@ function uninstall() {
126126
function update() {
127127
echo "Updating actions..."
128128
bx wsk action update $PACKAGE_NAME/auth-validate \
129-
actions/validate/build/libs/validate.jar \
130-
--main serverlessfollowup.auth.ValidateToken
129+
actions/validate/ValidateToken.swift \
130+
131+
bx wsk action update $PACKAGE_NAME/users-add \
132+
actions/users/AddUser.swift \
131133

132-
bx wsk action update $PACKAGE_NAME/users-add \
133-
actions/users/build/libs/users.jar \
134-
--main serverlessfollowup.users.AddUser
134+
bx wsk action update $PACKAGE_NAME/users-prepare-notify \
135+
actions/users/PrepareUserNotification.swift \
135136

136-
bx wsk action update $PACKAGE_NAME/users-prepare-notify \
137-
actions/users/build/libs/users.jar \
138-
--main serverlessfollowup.users.PrepareUserNotification
137+
bx wsk action update $PACKAGE_NAME/feedback-put \
138+
actions/feedback/AddFeedback.swift \
139139

140-
bx wsk action update $PACKAGE_NAME/feedback-put \
141-
actions/feedback/build/libs/feedback.jar \
142-
--main serverlessfollowup.feedback.AddFeedback
140+
bx wsk action update $PACKAGE_NAME/feedback-analyze \
141+
actions/feedback/AnalyzeFeedback.swift \
143142

144-
bx wsk action update $PACKAGE_NAME/feedback-analyze \
145-
actions/feedback/build/libs/feedback.jar \
146-
--main serverlessfollowup.feedback.AnalyzeFeedback
147143
}
148144

149145
function showenv() {

followupapp/FollowUpappid/AfterLoginViewController.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* limitations under the License.
1111
*/
1212

13-
1413
import UIKit
1514
import BluemixAppID
1615
import BMSCore
@@ -21,13 +20,8 @@ class AfterLoginViewController: UIViewController,UITextViewDelegate {
2120

2221
@IBOutlet weak var toptext: UILabel!
2322
@IBOutlet weak var profilePic: UIImageView!
24-
25-
@IBOutlet weak var hintMessageView: UILabel!
2623
@IBOutlet weak var topBar: UIView!
27-
@IBOutlet weak var nextLabel: UILabel!
2824
@IBOutlet weak var successMsg: UILabel!
29-
// function for displaying login
30-
// @IBOutlet weak var warningText: UILabel!
3125
@IBOutlet weak var submitButton: UIButton!
3226
@IBOutlet weak var feedbackText: UITextView!
3327
var accessToken:AccessToken?
@@ -126,6 +120,9 @@ class AfterLoginViewController: UIViewController,UITextViewDelegate {
126120

127121
}
128122

123+
/// Called by Submit button.
124+
///
125+
/// - Parameter sender: <#sender description#>
129126
@IBAction func submitFeedback(_ sender: Any) {
130127

131128
ServerlessAPI.sharedInstance.sendFeedback(accessToken: accessToken!,idToken: idToken!, message: feedbackText.text)

followupapp/FollowUpappid/AppDelegate.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import BluemixAppID
1919
class AppDelegate: UIResponder, UIApplicationDelegate {
2020

2121
var window: UIWindow?
22-
22+
var pushAppGUID: String?
23+
var pushClientSecret: String?
2324
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
2425

26+
//Initialize BMSCore SDK.
2527
let myBMSClient = BMSClient.sharedInstance
26-
myBMSClient.initialize(bluemixRegion:BMSClient.Region.sydney )
28+
myBMSClient.initialize(bluemixRegion:BMSClient.Region.sydney ) // TODO: Change to the region of push notifications service.
2729
myBMSClient.requestTimeout = 10.0 // seconds
2830

2931
// Initialize the AppID instance with your tenant ID and region
@@ -34,6 +36,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3436
let bmsclient = BMSClient.sharedInstance
3537
let backendGUID = dictionary["authTenantId"] as? String
3638
let serverlessBackendURL = dictionary["serverlessBackendUrl"] as? String
39+
pushAppGUID = dictionary["pushAppGuid"] as? String
40+
pushClientSecret = dictionary["pushClientSecret"] as? String
3741
bmsclient.initialize(bluemixRegion: region)
3842
let appid = AppID.sharedInstance
3943
appid.initialize(tenantId: backendGUID!, bluemixRegion: region)
@@ -42,6 +46,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4246
TokenStorageManager.sharedInstance.initialize(tenantId: backendGUID!)
4347
ServerlessAPI.sharedInstance.initialize(tenantId: backendGUID!,serverlessBackendURL: serverlessBackendURL!)
4448
}
49+
50+
51+
//Request for user permission to send push notifications
4552
let notificationSettings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)
4653
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
4754
UIApplication.shared.registerForRemoteNotifications()
@@ -52,6 +59,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5259
return AppID.sharedInstance.application(application, open: url, options: options)
5360
}
5461

62+
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
63+
let push = BMSPushClient.sharedInstance
64+
push.initializeWithAppGUID(appGUID: pushAppGUID!, clientSecret: pushClientSecret!)
65+
push.registerWithDeviceToken(deviceToken: deviceToken) { (response, statusCode, error) -> Void in
66+
if error.isEmpty {
67+
print( "Response during device registration : \(String(describing: response))")
68+
print( "status code during device registration : \(String(describing: statusCode))")
69+
} else{
70+
print( "Error during device registration \(error) ")
71+
print( "Error during device registration \n - status code: \(String(describing: statusCode)) \n Error :\(error) \n")
72+
}
73+
}
74+
}
75+
5576
func applicationWillResignActive(_ application: UIApplication) {
5677
// 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.
5778
// 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.

followupapp/FollowUpappid/BMSCredentials.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<key>appName</key>
88
<string>serverlessfollowupapp</string>
99
<key>serverlessBackendUrl</key>
10+
<string>https://openwhisk.ng.bluemix.net/api/v1/web/REPLACE-WITH-ORG-NAME_REPLACE-WITH-SPACE-NAME/serverlessfollowup</string>
11+
<key>pushAppGuid</key>
12+
<string></string>
13+
<key>pushClientSecret</key>
1014
<string></string>
1115
</dict>
1216
</plist>

followupapp/FollowUpappid/ServerlessAPI.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import BluemixAppID
1212

1313
public class ServerlessAPI{
1414

15+
1516
var idToken:IdentityToken?
1617
var accessToken:AccessToken?
1718
var tenantId : String?
@@ -24,6 +25,12 @@ public class ServerlessAPI{
2425
self.serverlessBackendURL = serverlessBackendURL
2526
}
2627

28+
29+
/// Send a request to serverless action to a user after validating the accesstoken
30+
///
31+
/// - Parameters:
32+
/// - accessToken: Provided by App ID
33+
/// - idToken: Provided by App ID
2734
func addUser(accessToken:AccessToken?, idToken:IdentityToken?)
2835
{
2936
self.accessToken = accessToken
@@ -62,6 +69,12 @@ public class ServerlessAPI{
6269
}
6370
}
6471

72+
/// Calls serverless action to add feedback to database.
73+
///
74+
/// - Parameters:
75+
/// - accessToken: Provided by AppID service.
76+
/// - idToken: Provided by AppID service
77+
/// - message: As entered in Feedback Text View
6578
func sendFeedback(accessToken:AccessToken?, idToken:IdentityToken?, message: String?)
6679
{
6780

0 commit comments

Comments
 (0)