Skip to content

Commit 79305ea

Browse files
committed
app Code
1 parent 920ca9c commit 79305ea

File tree

734 files changed

+79092
-0
lines changed

Some content is hidden

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

734 files changed

+79092
-0
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 3202 additions & 0 deletions
Large diffs are not rendered by default.

Coding_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Coding_iOS.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Coding_iOS/APIUrl.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// APIUrl.h
3+
// Coding_iOS
4+
//
5+
// Created by 王 原闯 on 14-7-30.
6+
// Copyright (c) 2014年 Coding. All rights reserved.
7+
//
8+
9+
#ifndef Coding_iOS_APIUrl_h
10+
#define Coding_iOS_APIUrl_h
11+
#endif
12+
13+
#define Code_CookieData @"sessionCookies"
14+
15+
/*api接口请求都放这里*/
16+
17+
#pragma mark BaseUrl
18+
//生产
19+
#define kNetPath_Code_Base @"https://coding.net/"
20+
21+
//测试
22+
//#define kNetPath_Code_Base @"https://staging.coding.net/"
23+
24+
//Jeffrey
25+
//#define kNetPath_Code_Base @"http://192.168.0.54:8080/"
26+
27+
#pragma mark ConfigUrl
28+
#define kNetPath_Code_Login @"api/login"

Coding_iOS/AppDelegate.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// AppDelegate.h
3+
// Coding_iOS
4+
//
5+
// Created by 王 原闯 on 14-7-29.
6+
// Copyright (c) 2014年 Coding. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
12+
13+
@property (strong, nonatomic) UIWindow *window;
14+
15+
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
16+
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
17+
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
18+
19+
- (void)saveContext;
20+
- (NSURL *)applicationDocumentsDirectory;
21+
22+
- (void)setupTabViewController;
23+
- (void)setupLoginViewController;
24+
/**
25+
* 注册推送
26+
*/
27+
- (void)registerPush;
28+
@end

Coding_iOS/AppDelegate.m

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
//
2+
// AppDelegate.m
3+
// Coding_iOS
4+
//
5+
// Created by 王 原闯 on 14-7-29.
6+
// Copyright (c) 2014年 Coding. All rights reserved.
7+
//
8+
9+
10+
#define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
11+
#define _IPHONE80_ 80000
12+
13+
14+
15+
#import "AppDelegate.h"
16+
#import "RootTabViewController.h"
17+
#import "LoginViewController.h"
18+
#import "AFNetworkActivityIndicatorManager.h"
19+
#import "Login.h"
20+
#import "UnReadManager.h"
21+
#import "UMessage.h"
22+
#import "XGPush.h"
23+
24+
@implementation AppDelegate
25+
26+
@synthesize managedObjectContext = _managedObjectContext;
27+
@synthesize managedObjectModel = _managedObjectModel;
28+
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
29+
30+
#pragma mark XGPush
31+
- (void)registerPush{
32+
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
33+
if(sysVer < 8){
34+
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
35+
}else{
36+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
37+
UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
38+
UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert
39+
categories:[NSSet setWithObject:categorys]];
40+
[[UIApplication sharedApplication] registerUserNotificationSettings:userSettings];
41+
[[UIApplication sharedApplication] registerForRemoteNotifications];
42+
#endif
43+
}
44+
}
45+
46+
47+
#pragma lifeCycle
48+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
49+
{
50+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
51+
// Override point for customization after application launch.
52+
self.window.backgroundColor = [UIColor whiteColor];
53+
54+
//网络指示标志
55+
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
56+
57+
//设置导航条样式
58+
[self customizeInterface];
59+
60+
61+
if ([Login isLogin]) {
62+
[self setupTabViewController];
63+
NSDictionary *remoteNotification = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
64+
if (remoteNotification) {
65+
NSDictionary *apsInfo = [remoteNotification objectForKey:@"aps"];
66+
[BaseViewController handleNotificationInfo:apsInfo];
67+
}
68+
}else{
69+
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
70+
[self setupLoginViewController];
71+
}
72+
73+
[self.window makeKeyAndVisible];
74+
// UMENG 统计
75+
[MobClick startWithAppkey:kUmeng_AppKey reportPolicy:BATCH channelId:nil];
76+
77+
// UMENG 推送
78+
//set AppKey and LaunchOptions
79+
[UMessage startWithAppkey:kUmeng_AppKey_Push launchOptions:launchOptions];
80+
[UMessage setBadgeClear:NO];
81+
[UMessage setLogEnabled:NO];
82+
83+
// 信鸽推送
84+
[XGPush startApp:kXGPush_Id appKey:kXGPush_Key];
85+
[Login setXGAccountWithCurUser];
86+
//注销之后需要再次注册前的准备
87+
void (^successCallback)(void) = ^(void){
88+
//如果变成需要注册状态
89+
if(![XGPush isUnRegisterStatus] && [Login isLogin]){
90+
[self registerPush];
91+
}
92+
};
93+
[XGPush initForReregister:successCallback];
94+
95+
//[XGPush registerPush]; //注册Push服务,注册后才能收到推送
96+
97+
//推送反馈(app不在前台运行时,点击推送激活时。统计而已)
98+
[XGPush handleLaunching:launchOptions];
99+
100+
return YES;
101+
}
102+
103+
- (void)applicationWillResignActive:(UIApplication *)application
104+
{
105+
// 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.
106+
// 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.
107+
}
108+
109+
- (void)applicationDidEnterBackground:(UIApplication *)application
110+
{
111+
// 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.
112+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
113+
[ImageSizeManager save];
114+
}
115+
116+
- (void)applicationWillEnterForeground:(UIApplication *)application
117+
{
118+
// 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.
119+
}
120+
121+
- (void)applicationDidBecomeActive:(UIApplication *)application
122+
{
123+
// 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.
124+
}
125+
126+
- (void)applicationWillTerminate:(UIApplication *)application
127+
{
128+
// Saves changes in the application's managed object context before the application terminates.
129+
[self saveContext];
130+
[ImageSizeManager save];
131+
}
132+
#pragma mark - Umeng Message
133+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
134+
{
135+
[UMessage registerDeviceToken:deviceToken];
136+
[Login addUmengAliasWithCurUser:[Login isLogin]];
137+
138+
NSString * deviceTokenStr = [XGPush registerDevice:deviceToken];
139+
NSLog(@"deviceTokenStr : %@", deviceTokenStr);
140+
}
141+
142+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
143+
{
144+
NSLog(@"didReceiveRemoteNotification-userInfo:-----\n%@", userInfo);
145+
146+
if ([application applicationState] == UIApplicationStateInactive) {
147+
//If the application state was inactive, this means the user pressed an action button
148+
// from a notification.
149+
[XGPush handleReceiveNotification:userInfo];
150+
151+
[BaseViewController handleNotificationInfo:userInfo];
152+
}else if ([application applicationState] == UIApplicationStateActive){
153+
// kTipAlert(@"UIApplicationStateActive");
154+
}
155+
}
156+
157+
#pragma mark - Methods Private
158+
- (void)setupLoginViewController{
159+
LoginViewController *loginVC = [[LoginViewController alloc] init];
160+
[self.window setRootViewController:[[UINavigationController alloc] initWithRootViewController:loginVC]];
161+
}
162+
163+
- (void)setupTabViewController{
164+
RootTabViewController *rootVC = [[RootTabViewController alloc] init];
165+
[self.window setRootViewController:rootVC];
166+
}
167+
168+
- (void)customizeInterface {
169+
//设置Nav的背景色和title色
170+
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
171+
NSDictionary *textAttributes = nil;
172+
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
173+
[navigationBarAppearance setTintColor:[UIColor whiteColor]];//返回按钮的箭头颜色
174+
[[UITextField appearance] setTintColor:[UIColor colorWithHexString:@"0x3bbc79"]];//设置UITextField的光标颜色
175+
[[UITextView appearance] setTintColor:[UIColor colorWithHexString:@"0x3bbc79"]];//设置UITextView的光标颜色
176+
[[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xe5e5e5"]] forBarPosition:0 barMetrics:UIBarMetricsDefault];
177+
178+
textAttributes = @{
179+
NSFontAttributeName: [UIFont boldSystemFontOfSize:kNavTitleFontSize],
180+
NSForegroundColorAttributeName: [UIColor whiteColor],
181+
};
182+
} else {
183+
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
184+
[[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xe5e5e5"]]];
185+
186+
textAttributes = @{
187+
UITextAttributeFont: [UIFont boldSystemFontOfSize:kNavTitleFontSize],
188+
UITextAttributeTextColor: [UIColor whiteColor],
189+
UITextAttributeTextShadowColor: [UIColor clearColor],
190+
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
191+
};
192+
#endif
193+
}
194+
[navigationBarAppearance setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0x28303b"]] forBarMetrics:UIBarMetricsDefault];
195+
[navigationBarAppearance setTitleTextAttributes:textAttributes];
196+
}
197+
198+
199+
#pragma mark - Methods Core Data
200+
201+
- (void)saveContext
202+
{
203+
NSError *error = nil;
204+
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
205+
if (managedObjectContext != nil) {
206+
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
207+
// Replace this implementation with code to handle the error appropriately.
208+
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
209+
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
210+
abort();
211+
}
212+
}
213+
}
214+
215+
#pragma mark - Core Data stack
216+
217+
// Returns the managed object context for the application.
218+
// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
219+
- (NSManagedObjectContext *)managedObjectContext
220+
{
221+
if (_managedObjectContext != nil) {
222+
return _managedObjectContext;
223+
}
224+
225+
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
226+
if (coordinator != nil) {
227+
_managedObjectContext = [[NSManagedObjectContext alloc] init];
228+
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
229+
}
230+
return _managedObjectContext;
231+
}
232+
233+
// Returns the managed object model for the application.
234+
// If the model doesn't already exist, it is created from the application's model.
235+
- (NSManagedObjectModel *)managedObjectModel
236+
{
237+
if (_managedObjectModel != nil) {
238+
return _managedObjectModel;
239+
}
240+
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Coding_iOS" withExtension:@"momd"];
241+
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
242+
return _managedObjectModel;
243+
}
244+
245+
// Returns the persistent store coordinator for the application.
246+
// If the coordinator doesn't already exist, it is created and the application's store added to it.
247+
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
248+
{
249+
if (_persistentStoreCoordinator != nil) {
250+
return _persistentStoreCoordinator;
251+
}
252+
253+
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Coding_iOS.sqlite"];
254+
255+
NSError *error = nil;
256+
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
257+
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
258+
/*
259+
Replace this implementation with code to handle the error appropriately.
260+
261+
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
262+
263+
Typical reasons for an error here include:
264+
* The persistent store is not accessible;
265+
* The schema for the persistent store is incompatible with current managed object model.
266+
Check the error message to determine what the actual problem was.
267+
268+
269+
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
270+
271+
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
272+
* Simply deleting the existing store:
273+
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
274+
275+
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
276+
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
277+
278+
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
279+
280+
*/
281+
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
282+
abort();
283+
}
284+
285+
return _persistentStoreCoordinator;
286+
}
287+
288+
#pragma mark - Application's Documents directory
289+
290+
// Returns the URL to the application's Documents directory.
291+
- (NSURL *)applicationDocumentsDirectory
292+
{
293+
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
294+
}
295+
296+
@end

0 commit comments

Comments
 (0)