Skip to content

Commit 6b33250

Browse files
committed
Merge branch 'swift-2.3'
2 parents 349101b + 222b161 commit 6b33250

File tree

14 files changed

+87
-48
lines changed

14 files changed

+87
-48
lines changed

Podfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use_frameworks!
22
target 'ruby-china-ios' do
33
pod 'Turbolinks', git: 'https://github.com/turbolinks/turbolinks-ios.git'
4-
pod 'SideMenu'
5-
pod 'SwiftyJSON'
6-
pod 'Alamofire'
7-
pod 'Heimdallr'
4+
pod 'SideMenu', '~> 1.0'
5+
pod 'SwiftyJSON', '~> 2.0'
6+
pod 'Alamofire', '~> 3.0'
7+
pod 'Heimdallr', '~> 3.0'
88
pod 'Router'
99
pod 'PKHUD'
1010
pod 'YYKeyboardManager'

Podfile.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
PODS:
2-
- Alamofire (3.4.1)
3-
- Heimdallr (3.3.1):
4-
- Heimdallr/Core (= 3.3.1)
5-
- Heimdallr/Core (3.3.1):
2+
- Alamofire (3.5.0)
3+
- Heimdallr (3.5.0):
4+
- Heimdallr/Core (= 3.5.0)
5+
- Heimdallr/Core (3.5.0):
66
- Result (~> 2.0)
77
- PKHUD (3.2.1)
88
- Result (2.1.3)
99
- Router (1.0.0)
10-
- SideMenu (1.1.9)
11-
- SwiftyJSON (2.3.2)
10+
- SideMenu (1.2.1)
11+
- SwiftyJSON (2.4.0)
1212
- Turbolinks (1.0.2)
1313
- YYKeyboardManager (1.0.1)
1414

1515
DEPENDENCIES:
16-
- Alamofire
17-
- Heimdallr
16+
- Alamofire (~> 3.0)
17+
- Heimdallr (~> 3.0)
1818
- PKHUD
1919
- Router
20-
- SideMenu
21-
- SwiftyJSON
20+
- SideMenu (~> 1.0)
21+
- SwiftyJSON (~> 2.0)
2222
- Turbolinks (from `https://github.com/turbolinks/turbolinks-ios.git`)
2323
- YYKeyboardManager
2424

@@ -28,20 +28,20 @@ EXTERNAL SOURCES:
2828

2929
CHECKOUT OPTIONS:
3030
Turbolinks:
31-
:commit: b8702ffd6e06748120a678949fdde6dfc3edd397
31+
:commit: 27379cfdf0454636505d99251ca32f2b506547eb
3232
:git: https://github.com/turbolinks/turbolinks-ios.git
3333

3434
SPEC CHECKSUMS:
35-
Alamofire: 01a82e2f6c0f860ade35534c8dd88be61bdef40c
36-
Heimdallr: db5f669f3666cb0dc5ad326538fee3f6f8044417
35+
Alamofire: b70a7352335f8ea5babd0a923eb7e8eacc67b877
36+
Heimdallr: 5451a68028a6dc02f009fb6b73923d7f88b702c7
3737
PKHUD: 001c11518f125a273ddf026bcc64918423744ea2
3838
Result: 18e1a7597fbcca5923c565b40a25a98afafdee02
3939
Router: 6088d6d321e097070d5ea4bd792cb015dfa0fbb4
40-
SideMenu: e4ecb0f1061e19230e53079edb2b300081446f80
41-
SwiftyJSON: 04ccea08915aa0109039157c7974cf0298da292a
40+
SideMenu: d38e42ab18a5c0875a77cfec7e7cecea72a69518
41+
SwiftyJSON: 96918c1bf505efa50c4f72957018dd3452090c9c
4242
Turbolinks: d8209bab43803adae8c06d434368e16479023407
4343
YYKeyboardManager: ff53d2e80d1808567a7f004028bd200d9469a89f
4444

45-
PODFILE CHECKSUM: 60fa3209794e9fabd0cf6b737e3cf51c7fca9966
45+
PODFILE CHECKSUM: 928e24527cf5c8a8c48eec9f686eddff815a5b93
4646

47-
COCOAPODS: 1.0.1
47+
COCOAPODS: 1.1.0.rc.2

ruby-china-ios.xcodeproj/project.pbxproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,13 @@
242242
isa = PBXProject;
243243
attributes = {
244244
LastSwiftUpdateCheck = 0730;
245-
LastUpgradeCheck = 0730;
245+
LastUpgradeCheck = 0800;
246246
ORGANIZATIONNAME = "ruby-china";
247247
TargetAttributes = {
248248
9670F18B1D4235D200128F8A = {
249249
CreatedOnToolsVersion = 7.3.1;
250250
DevelopmentTeam = A38T799N53;
251+
LastSwiftMigration = 0800;
251252
SystemCapabilities = {
252253
com.apple.Push = {
253254
enabled = 1;
@@ -305,7 +306,7 @@
305306
);
306307
runOnlyForDeploymentPostprocessing = 0;
307308
shellPath = /bin/sh;
308-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
309+
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
309310
showEnvVarsInLog = 0;
310311
};
311312
A493C2F4C2D843A7EC1873C7 /* [CP] Embed Pods Frameworks */ = {
@@ -494,6 +495,7 @@
494495
PRODUCT_BUNDLE_IDENTIFIER = "org.ruby-china.app";
495496
PRODUCT_NAME = "Ruby China";
496497
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
498+
SWIFT_VERSION = 2.3;
497499
};
498500
name = Debug;
499501
};
@@ -509,6 +511,7 @@
509511
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
510512
PRODUCT_BUNDLE_IDENTIFIER = "org.ruby-china.app";
511513
PRODUCT_NAME = "Ruby China";
514+
SWIFT_VERSION = 2.3;
512515
};
513516
name = Release;
514517
};

ruby-china-ios/Controllers/RootViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RootViewController: UITabBarController {
4646
viewControllers = [topicsController, pagesController, favoritesController, notificationsController]
4747
viewControllers?.forEach({ (viewController) in
4848
let oldImage = viewController.tabBarItem.image
49-
viewController.tabBarItem.image = oldImage?.imageWithColor(BLACK_COLOR).imageWithRenderingMode(.AlwaysOriginal)
49+
viewController.tabBarItem.image = oldImage?.imageWithColor(BLACK_COLOR)?.imageWithRenderingMode(.AlwaysOriginal)
5050
})
5151
}
5252

ruby-china-ios/Controllers/SideMenuViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ class SideMenuViewController: UITableViewController {
120120
guard let `self` = self else {
121121
return
122122
}
123-
let avatarImage = avatar.drawRectWithRoundedCorner(radius: 11, CGSizeMake(22, 22))
123+
guard let avatarImage = avatar.drawRectWithRoundedCorner(radius: 11, CGSizeMake(22, 22)) else {
124+
return
125+
}
124126
self.menuItemIcons[0] = avatarImage
125127
self.tableView.reloadData()
126128
})

ruby-china-ios/Controllers/SignInViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension SignInViewController: OAuth2Delegate {
155155
}
156156

157157
func oauth2DidLoginFailed(error: NSError) {
158-
print("Login failed", error.localizedFailureReason)
158+
print("Login failed", error)
159159

160160
var errorMessage = ""
161161
if error.code == 3 {

ruby-china-ios/Controllers/WebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class WebViewController: VisitableViewController {
140140
}
141141

142142
lazy var errorView: ErrorView = {
143-
let view = NSBundle.mainBundle().loadNibNamed("ErrorView", owner: self, options: nil).first as! ErrorView
143+
let view = NSBundle.mainBundle().loadNibNamed("ErrorView", owner: self, options: nil)!.first as! ErrorView
144144
view.translatesAutoresizingMaskIntoConstraints = false
145145
view.retryButton.addTarget(self, action: #selector(retry(_:)), forControlEvents: .TouchUpInside)
146146
return view

ruby-china-ios/Extensions/UIImage+Ext.swift

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ extension UIImage {
1717

1818
- returns: 图片
1919
*/
20-
static func fromColor(color: UIColor) -> UIImage {
20+
static func fromColor(color: UIColor) -> UIImage? {
2121
let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
2222
UIGraphicsBeginImageContext(rect.size)
23-
let context = UIGraphicsGetCurrentContext()
23+
guard let context = UIGraphicsGetCurrentContext() else {
24+
UIGraphicsEndImageContext()
25+
return nil
26+
}
2427
CGContextSetFillColorWithColor(context, color.CGColor)
2528
CGContextFillRect(context, rect)
2629
let img = UIGraphicsGetImageFromCurrentImageContext()
@@ -36,17 +39,21 @@ extension UIImage {
3639

3740
- returns: 圆角图片
3841
*/
39-
func drawRectWithRoundedCorner(radius radius: CGFloat, _ sizetoFit: CGSize) -> UIImage {
42+
func drawRectWithRoundedCorner(radius radius: CGFloat, _ sizetoFit: CGSize) -> UIImage? {
4043
let rect = CGRect(origin: CGPoint(x: 0, y: 0), size: sizetoFit)
4144

4245
UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.mainScreen().scale)
43-
CGContextAddPath(UIGraphicsGetCurrentContext(),
44-
UIBezierPath(roundedRect: rect, byRoundingCorners: UIRectCorner.AllCorners,
45-
cornerRadii: CGSize(width: radius, height: radius)).CGPath)
46-
CGContextClip(UIGraphicsGetCurrentContext())
46+
guard let context = UIGraphicsGetCurrentContext() else {
47+
UIGraphicsEndImageContext()
48+
return nil
49+
}
50+
51+
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: .AllCorners, cornerRadii: CGSize(width: radius, height: radius))
52+
CGContextAddPath(context, path.CGPath)
53+
CGContextClip(context)
4754

4855
self.drawInRect(rect)
49-
CGContextDrawPath(UIGraphicsGetCurrentContext(), .FillStroke)
56+
CGContextDrawPath(context, .FillStroke)
5057
let output = UIGraphicsGetImageFromCurrentImageContext()
5158
UIGraphicsEndImageContext()
5259

@@ -60,17 +67,26 @@ extension UIImage {
6067

6168
- returns: 新图片
6269
*/
63-
func imageWithColor(color: UIColor) -> UIImage {
70+
func imageWithColor(color: UIColor) -> UIImage? {
71+
guard let cgimage = CGImage else {
72+
return nil
73+
}
74+
6475
UIGraphicsBeginImageContextWithOptions(size, false, scale)
65-
let context = UIGraphicsGetCurrentContext()
76+
guard let context = UIGraphicsGetCurrentContext() else {
77+
UIGraphicsEndImageContext()
78+
return nil
79+
}
80+
6681
CGContextTranslateCTM(context, 0, size.height)
6782
CGContextScaleCTM(context, 1.0, -1.0)
6883
CGContextSetBlendMode(context, .Normal)
6984
let rect = CGRectMake(0, 0, size.width, size.height)
70-
CGContextClipToMask(context, rect, CGImage)
85+
CGContextClipToMask(context, rect, cgimage)
7186
color.setFill()
7287
CGContextFillRect(context, rect)
7388
let newImage = UIGraphicsGetImageFromCurrentImageContext()
89+
7490
UIGraphicsEndImageContext()
7591
return newImage
7692
}

ruby-china-ios/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<key>NSAllowsArbitraryLoads</key>
3232
<true/>
3333
</dict>
34+
<key>NSCameraUsageDescription</key>
35+
<string>上传照片</string>
36+
<key>NSPhotoLibraryUsageDescription</key>
37+
<string>上传照片</string>
3438
<key>UIMainStoryboardFile</key>
3539
<string>Main</string>
3640
<key>UIRequiredDeviceCapabilities</key>

ruby-china-ios/Libraries/OAuth2.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ class OAuth2 {
5050
heimdallr.requestAccessToken(username: username, password: password) { result in
5151
switch result {
5252
case .Success:
53-
self.accessToken = self.accessTokenStore.retrieveAccessToken()?.accessToken
54-
print("accessToken", self.accessToken)
53+
guard let accessToken = self.accessTokenStore.retrieveAccessToken()?.accessToken else {
54+
print("Login is successful but the access_Token is missing")
55+
let err = NSError(domain: "customize", code: -1, userInfo: [NSLocalizedDescriptionKey: "get accessToken failed".localized])
56+
dispatch_async(dispatch_get_main_queue(), {
57+
self.delegate?.oauth2DidLoginFailed(err)
58+
})
59+
return
60+
}
61+
print("Login successed. accessToken=\(accessToken)")
62+
self.accessToken = accessToken
5563
self.submitDeviceToken()
56-
5764
self.reloadCurrentUser()
58-
print("Login successed.")
5965
dispatch_async(dispatch_get_main_queue(), {
60-
self.delegate?.oauth2DidLoginSuccessed(self.accessToken!)
66+
self.delegate?.oauth2DidLoginSuccessed(accessToken)
6167
})
6268
case .Failure(let err):
6369
dispatch_async(dispatch_get_main_queue(), {

0 commit comments

Comments
 (0)