Skip to content
This repository was archived by the owner on May 23, 2019. It is now read-only.

Commit 3fba94c

Browse files
committed
Merge branch 'develop'
2 parents 54fc3ea + 3ff5905 commit 3fba94c

File tree

71 files changed

+1932
-1009
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1932
-1009
lines changed

BluePic-Server/.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DEVELOPMENT-SNAPSHOT-2016-06-06-a
1+
DEVELOPMENT-SNAPSHOT-2016-06-20-a

BluePic-Server/Package.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import PackageDescription
1919
let package = Package(
2020
name: "BluePic-Server",
2121
dependencies: [
22-
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 19),
23-
.Package(url: "https://github.com/IBM-Swift/Kitura-CouchDB.git", majorVersion: 0, minor: 19),
24-
.Package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", majorVersion: 1, minor: 3),
25-
.Package(url: "https://github.com/ibm-bluemix-mobile-services/bluemix-objectstorage-swift-sdk.git", majorVersion: 0, minor: 4),
26-
.Package(url: "https://github.com/ibm-bluemix-mobile-services/bms-mca-kitura-credentials-plugin.git", majorVersion: 0, minor: 2),
27-
.Package(url: "https://github.com/ibm-bluemix-mobile-services/bms-pushnotifications-serversdk-swift.git", majorVersion: 0, minor: 2)
22+
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 22),
23+
.Package(url: "https://github.com/IBM-Swift/Kitura-CouchDB.git", majorVersion: 0, minor: 22),
24+
.Package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", majorVersion: 1, minor: 4),
25+
.Package(url: "https://github.com/ibm-bluemix-mobile-services/bluemix-objectstorage-swift-sdk.git", majorVersion: 0, minor: 5),
26+
.Package(url: "https://github.com/ibm-bluemix-mobile-services/bms-mca-kitura-credentials-plugin.git", majorVersion: 0, minor: 3),
27+
.Package(url: "https://github.com/ibm-bluemix-mobile-services/bms-pushnotifications-serversdk-swift.git", majorVersion: 0, minor: 3)
2828
],
2929
exclude: ["Makefile", "Kitura-Build"]
3030
)

BluePic-Server/Sources/Server/Configuration.swift

+12-5
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ public struct Configuration {
147147
hostName = openWhiskJson["hostName"].string,
148148
urlPath = openWhiskJson["urlPath"].string,
149149
authToken = openWhiskJson["authToken"].string {
150-
let utf8BaseStr = authToken.data(using: NSUTF8StringEncoding)
151-
guard let computedAuthToken = utf8BaseStr?.base64EncodedString(NSDataBase64EncodingOptions(rawValue: 0)) else {
152-
throw Error.IO("Could not perform base64 encoding on authToken")
153-
}
150+
#if os(OSX)
151+
let utf8BaseStr = authToken.data(using: String.Encoding.utf8)
152+
guard let computedAuthToken = utf8BaseStr?.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0)) else {
153+
throw Error.IO("Could not perform base64 encoding on authToken")
154+
}
155+
#else
156+
let utf8BaseStr = authToken.data(using: NSUTF8StringEncoding)
157+
guard let computedAuthToken = utf8BaseStr?.base64EncodedString(NSDataBase64EncodingOptions(rawValue: 0)) else {
158+
throw Error.IO("Could not perform base64 encoding on authToken")
159+
}
160+
#endif
154161
return OpenWhiskProps(hostName: hostName, urlPath: urlPath, authToken: computedAuthToken)
155162
}
156163
}
@@ -166,7 +173,7 @@ public struct Configuration {
166173
#if os(Linux)
167174
let fileManager = NSFileManager.defaultManager()
168175
#else
169-
let fileManager = NSFileManager.default()
176+
let fileManager = FileManager.default()
170177
#endif
171178

172179
if fileManager.fileExists(atPath: filePath) {

BluePic-Server/Sources/Server/ObjectStorageConn.swift

+23-16
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import Dispatch
2121

2222
// FIXME: Change to a struct when using a swift binary that supports the DispatchQueue type
2323
public class ObjectStorageConn {
24-
let connectQueue = dispatch_queue_create("connectQueue", nil)
24+
#if os(OSX)
25+
let connectQueue = DispatchQueue(label: "connectQueue")
26+
#else
27+
let connectQueue = dispatch_queue_create("connectQueue", nil)
28+
#endif
2529
let objStorage: ObjectStorage
2630
var test = 10
2731
let connProps: ObjectStorageConnProps
@@ -36,15 +40,14 @@ public class ObjectStorageConn {
3640
func getObjectStorage(completionHandler: (objStorage: ObjectStorage?) -> Void) {
3741
Log.verbose("Starting task in serialized block (getting ObjectStorage instance)...")
3842
#if os(OSX)
39-
guard let connectQueue = self.connectQueue else {
40-
Log.warning("Connect queue was not created properly")
41-
completionHandler(objStorage: nil)
42-
return
43+
connectQueue.sync {
44+
self.connect(completionHandler: completionHandler)
45+
}
46+
#else
47+
dispatch_sync(connectQueue) {
48+
self.connect(completionHandler: completionHandler)
4349
}
4450
#endif
45-
dispatch_sync(connectQueue) {
46-
self.connect(completionHandler: completionHandler)
47-
}
4851
Log.verbose("Completed task in serialized block.")
4952
let param: ObjectStorage? = (authenticated) ? objStorage : nil
5053
completionHandler(objStorage: param)
@@ -58,7 +61,7 @@ public class ObjectStorageConn {
5861
// This logic is just a stopgap solution to avoid requesting a new
5962
// authToken for every ObjectStorage request.
6063
// The ObjectStorage SDK will contain logic for handling expired authToken
61-
let timeDiff: NSTimeInterval = lastAuthenticatedTs.timeIntervalSinceNow
64+
let timeDiff = lastAuthenticatedTs.timeIntervalSinceNow
6265
let minsDiff = Int(fabs(timeDiff / 60))
6366
if minsDiff < 50 {
6467
Log.verbose("Reusing existing Object Storage auth token...")
@@ -68,11 +71,7 @@ public class ObjectStorageConn {
6871

6972
// Network call should be synchronous since we need to know the result before proceeding.
7073
#if os(OSX)
71-
guard let semaphore = dispatch_semaphore_create(0) else {
72-
Log.warning("Couldn't create semaphore...")
73-
completionHandler(objStorage: nil)
74-
return
75-
}
74+
let semaphore = DispatchSemaphore(value: 0)
7675
#else
7776
let semaphore = dispatch_semaphore_create(0)
7877
#endif
@@ -90,9 +89,17 @@ public class ObjectStorageConn {
9089
Log.verbose("lastAuthenticatedTs is \(self.lastAuthenticatedTs).")
9190
}
9291
Log.verbose("Signaling semaphore...")
93-
dispatch_semaphore_signal(semaphore)
92+
#if os(OSX)
93+
semaphore.signal()
94+
#else
95+
dispatch_semaphore_signal(semaphore)
96+
#endif
9497
}
95-
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
98+
#if os(OSX)
99+
let _ = semaphore.wait(timeout: DispatchTime.distantFuture)
100+
#else
101+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
102+
#endif
96103
Log.verbose("Continuing execution after synchronous network call...")
97104
}
98105

BluePic-Server/Sources/Server/RouteUtils.swift

+21-5
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,28 @@ func processImage(withId imageId: String) {
6767
if let resp = resp {
6868
Log.error("Status code: \(resp.statusCode)")
6969
if let rawUserData = try? BodyParser.readBodyData(with: resp) {
70-
let str = NSString(data: rawUserData, encoding: NSUTF8StringEncoding)
70+
#if os(OSX)
71+
let str = NSString(data: rawUserData as Data, encoding: String.Encoding.utf8.rawValue)
72+
#else
73+
let str = NSString(data: rawUserData, encoding: NSUTF8StringEncoding)
74+
#endif
7175
print("Error response from OpenWhisk: \(str)")
7276
}
7377
}
7478
}
7579
}
7680
// Kitura does not yet execute certain functionaliy asynchronously,
7781
// hence the need for this block.
78-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
79-
req.end(requestBody)
80-
}
82+
#if os(OSX)
83+
DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosDefault).async {
84+
req.end(requestBody)
85+
}
86+
#else
87+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
88+
req.end(requestBody)
89+
}
90+
#endif
91+
8192
}
8293

8394
/**
@@ -197,7 +208,12 @@ func parseMultipart(fromRequest request: RouterRequest) throws -> (JSON, NSData)
197208
if part.name == "imageJson" {
198209
switch (part.body) {
199210
case .text(let stringJson):
200-
if let dataJson = stringJson.data(using: NSUTF8StringEncoding, allowLossyConversion: false) {
211+
#if os(OSX)
212+
let encoding = String.Encoding.utf8
213+
#else
214+
let encoding = NSUTF8StringEncoding
215+
#endif
216+
if let dataJson = stringJson.data(using: encoding, allowLossyConversion: false) {
201217
imageJson = JSON(data: dataJson)
202218
}
203219
default:

BluePic-Server/Sources/Server/Routes.swift

+17-5
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ func defineRoutes() {
6060
errorResponse["error"].stringValue = "Failed to retrieve MCA token."
6161

6262
let baseStr = "\(mobileClientAccessProps.clientId):\(mobileClientAccessProps.secret)"
63-
print("baseStr: \(baseStr)")
64-
let utf8BaseStr = baseStr.data(using: NSUTF8StringEncoding)
65-
guard let authHeader = utf8BaseStr?.base64EncodedString(NSDataBase64EncodingOptions(rawValue: 0)) else {
63+
64+
var tempAuthHeader: String?
65+
#if os(OSX)
66+
let utf8BaseStr = baseStr.data(using: String.Encoding.utf8)
67+
tempAuthHeader = utf8BaseStr?.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
68+
#else
69+
let utf8BaseStr = baseStr.data(using: NSUTF8StringEncoding)
70+
tempAuthHeader = utf8BaseStr?.base64EncodedString(NSDataBase64EncodingOptions(rawValue: 0))
71+
#endif
72+
73+
guard let authHeader = tempAuthHeader else {
6674
print("Could not generate authHeader...")
6775
response.status(HTTPStatusCode.internalServerError).send(json: errorResponse)
6876
next()
@@ -108,7 +116,11 @@ func defineRoutes() {
108116
if let resp = resp {
109117
Log.error("Status code: \(resp.statusCode)")
110118
if let rawUserData = try? BodyParser.readBodyData(with: resp) {
111-
let str = NSString(data: rawUserData, encoding: NSUTF8StringEncoding)
119+
#if os(OSX)
120+
let str = NSString(data: rawUserData as Data, encoding: String.Encoding.utf8.rawValue)
121+
#else
122+
let str = NSString(data: rawUserData, encoding: NSUTF8StringEncoding)
123+
#endif
112124
print("Response from MCA server: \(str)")
113125
}
114126
}
@@ -256,7 +268,7 @@ func defineRoutes() {
256268
readImage(database: database, imageId: imageId) { (jsonImage) in
257269
if let jsonImage = jsonImage {
258270
let apnsSettings = Notification.Settings.Apns(badge: nil, category: "imageProcessed", iosActionKey: nil, sound: nil, type: ApnsType.DEFAULT, payload: jsonImage.dictionaryObject)
259-
let target = Notification.Target(deviceIds: [jsonImage["deviceId"].stringValue], platforms: [TargetPlatform.Apple], tagNames: nil)
271+
let target = Notification.Target(deviceIds: [jsonImage["deviceId"].stringValue], userIds: nil, platforms: [TargetPlatform.Apple], tagNames: nil)
260272
let message = Notification.Message(alert: "Your image was processed; check it out!", url: nil)
261273
let notification = Notification(message: message, target: target, apnsSettings: apnsSettings, gcmSettings: nil)
262274
pushNotificationsClient.send(notification: notification) { (error) in

BluePic-Server/docker-compose.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# To use this file, simply execute: docker-compose up
2+
app:
3+
image: ibmcom/kitura-ubuntu
4+
ports:
5+
- "8090:8090"
6+
volumes:
7+
- .:/root/BluePic
8+
command: bash -c "make clean -C BluePic && make -C BluePic && BluePic/.build/debug/Server"

BluePic-iOS/BluePic.xcodeproj/project.pbxproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
isa = PBXProject;
463463
attributes = {
464464
LastSwiftUpdateCheck = 0710;
465-
LastUpgradeCheck = 0710;
465+
LastUpgradeCheck = 0800;
466466
ORGANIZATIONNAME = MIL;
467467
TargetAttributes = {
468468
347472891BFA8C6A0018B7F6 = {
@@ -870,7 +870,7 @@
870870
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
871871
MTL_ENABLE_DEBUG_INFO = NO;
872872
SDKROOT = iphoneos;
873-
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
873+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
874874
TARGETED_DEVICE_FAMILY = "1,2";
875875
USER_HEADER_SEARCH_PATHS = "";
876876
VALIDATE_PRODUCT = YES;
@@ -881,6 +881,7 @@
881881
isa = XCBuildConfiguration;
882882
baseConfigurationReference = 6B961243483EA182951704B4 /* Pods-BluePic.debug.xcconfig */;
883883
buildSettings = {
884+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
884885
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
885886
CLANG_ENABLE_MODULES = YES;
886887
CODE_SIGN_ENTITLEMENTS = BluePic/BluePic.entitlements;
@@ -897,6 +898,7 @@
897898
PRODUCT_NAME = "$(TARGET_NAME)";
898899
SWIFT_OBJC_BRIDGING_HEADER = "BluePic/SupportingFiles/BluePic-Bridging-Header.h";
899900
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
901+
SWIFT_VERSION = 2.3;
900902
TARGETED_DEVICE_FAMILY = 1;
901903
};
902904
name = Debug;
@@ -905,6 +907,7 @@
905907
isa = XCBuildConfiguration;
906908
baseConfigurationReference = D4256EC7B8C927E2AAE77625 /* Pods-BluePic.release.xcconfig */;
907909
buildSettings = {
910+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
908911
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
909912
CLANG_ENABLE_MODULES = YES;
910913
CODE_SIGN_ENTITLEMENTS = BluePic/BluePic.entitlements;
@@ -920,6 +923,7 @@
920923
PRODUCT_BUNDLE_IDENTIFIER = com.ibm.test1;
921924
PRODUCT_NAME = "$(TARGET_NAME)";
922925
SWIFT_OBJC_BRIDGING_HEADER = "BluePic/SupportingFiles/BluePic-Bridging-Header.h";
926+
SWIFT_VERSION = 2.3;
923927
TARGETED_DEVICE_FAMILY = 1;
924928
};
925929
name = Release;
@@ -932,6 +936,7 @@
932936
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
933937
PRODUCT_BUNDLE_IDENTIFIER = com.bundle.id.BluePicTests;
934938
PRODUCT_NAME = "$(TARGET_NAME)";
939+
SWIFT_VERSION = 2.3;
935940
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BluePic.app/BluePic";
936941
};
937942
name = Debug;
@@ -944,6 +949,7 @@
944949
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
945950
PRODUCT_BUNDLE_IDENTIFIER = com.bundle.id.ibm.BluePicTests;
946951
PRODUCT_NAME = "$(TARGET_NAME)";
952+
SWIFT_VERSION = 2.3;
947953
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/BluePic.app/BluePic";
948954
};
949955
name = Release;

BluePic-iOS/BluePic.xcodeproj/xcshareddata/xcschemes/BluePic.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0710"
3+
LastUpgradeVersion = "0800"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

BluePic-iOS/BluePic/AppDelegate.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5555
*/
5656
func application (application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
5757
let push = BMSPushClient.sharedInstance
58-
push.registerDeviceToken(deviceToken) { (response, statusCode, error) -> Void in
58+
push.initializeWithAppGUID(BluemixDataManager.SharedInstance.bluemixConfig.appGUID)
59+
push.registerWithDeviceToken(deviceToken) { (response, statusCode, error) in
5960
if error.isEmpty {
6061
print( "Response during device registration : \(response)")
6162
print( "status code during device registration : \(statusCode)")
@@ -64,7 +65,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6465
print( "Error during device registration \n - status code: \(statusCode) \n Error :\(error) \n")
6566
}
6667
}
67-
6868
}
6969

7070
/**

BluePic-iOS/BluePic/Configuration/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSPhotoLibraryUsageDescription</key>
6+
<string>We access your photos so you can pick the right one to upload.</string>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>en</string>
79
<key>CFBundleExecutable</key>

BluePic-iOS/BluePic/Extensions/UIImageExtension.swift

+11-6
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ extension UIImage {
6060
let rect = CGRect(x: 0, y: 0, width: actualWidth, height: actualHeight)
6161
UIGraphicsBeginImageContext(rect.size)
6262
image.drawInRect(rect)
63-
let img = UIGraphicsGetImageFromCurrentImageContext()
64-
let imageData = UIImageJPEGRepresentation(img, compressionQuality)
63+
var imageData: NSData?
64+
if let img = UIGraphicsGetImageFromCurrentImageContext() {
65+
imageData = UIImageJPEGRepresentation(img, compressionQuality)
66+
}
6567
UIGraphicsEndImageContext()
6668

6769
if let data = imageData {
@@ -79,7 +81,7 @@ extension UIImage {
7981

8082
- returns: UIImage
8183
*/
82-
class func rotateImageIfNecessary(imageToRotate: UIImage) -> UIImage {
84+
class func rotateImageIfNecessary(imageToRotate: UIImage) -> UIImage? {
8385
let imageOrientation = imageToRotate.imageOrientation.rawValue
8486
switch imageOrientation {
8587
case 0: //Up
@@ -103,7 +105,7 @@ extension UIImage {
103105

104106
- returns: UIImage
105107
*/
106-
public func imageRotatedByDegrees(degrees: CGFloat, flip: Bool) -> UIImage {
108+
public func imageRotatedByDegrees(degrees: CGFloat, flip: Bool) -> UIImage? {
107109
let degreesToRadians: (CGFloat) -> CGFloat = {
108110
return $0 / 180.0 * CGFloat(M_PI)
109111
}
@@ -116,7 +118,10 @@ extension UIImage {
116118

117119
// Create the bitmap context
118120
UIGraphicsBeginImageContext(rotatedSize)
119-
let bitmap = UIGraphicsGetCurrentContext()
121+
guard let bitmap = UIGraphicsGetCurrentContext() else {
122+
print("Failed to get bitmap from context")
123+
return nil
124+
}
120125

121126
// Move the origin to the middle of the image so we will rotate and scale around the center.
122127
CGContextTranslateCTM(bitmap, rotatedSize.width / 2.0, rotatedSize.height / 2.0)
@@ -134,7 +139,7 @@ extension UIImage {
134139
}
135140

136141
CGContextScaleCTM(bitmap, yFlip, -1.0)
137-
CGContextDrawImage(bitmap, CGRect(x: -size.width / 2, y: -size.height / 2, width: size.width, height: size.height), CGImage)
142+
CGContextDrawImage(bitmap, CGRect(x: -size.width / 2, y: -size.height / 2, width: size.width, height: size.height), self.CGImage!)
138143

139144
let newImage = UIGraphicsGetImageFromCurrentImageContext()
140145
UIGraphicsEndImageContext()

BluePic-iOS/Podfile

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ target 'BluePic' do
66

77
pod 'BMSFacebookAuthentication'
88

9-
pod 'BMSSecurity', :git => 'https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-swift-security.git'
10-
119
pod 'BMSPush'
1210

1311
pod 'SDWebImage', '~>3.7'

0 commit comments

Comments
 (0)