Skip to content

Commit eb64ecb

Browse files
committed
代码开源;
0 parents  commit eb64ecb

File tree

2,265 files changed

+193759
-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.

2,265 files changed

+193759
-0
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Xcode
2+
build/*
3+
*.pbxuser
4+
!default.pbxuser
5+
*.mode1v3
6+
!default.mode1v3
7+
*.mode2v3
8+
!default.mode2v3
9+
*.perspectivev3
10+
!default.perspectivev3
11+
!default.xcworkspace
12+
xcuserdata
13+
profile
14+
*.moved-aside
15+
.DS_Store
16+
.svn
17+
*.swp
18+
.data.html.swp
19+
*.pyc
20+
.data.html.swp
21+
*.sqlite
22+
.idea
23+
.Rhistory
24+
*.xccheckout
25+
*.xcscmblueprint
26+
Config.h

CodingForiPad.xcodeproj/project.pbxproj

+2,879
Large diffs are not rendered by default.

CodingForiPad.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingForiPad.xcworkspace/contents.xcworkspacedata

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingForiPad/AppDelegate.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// AppDelegate.h
3+
// CodingForiPad
4+
//
5+
// Created by sunguanglei on 15/6/8.
6+
// Copyright (c) 2015年 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+
16+
@end
17+

CodingForiPad/AppDelegate.m

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
//
2+
// AppDelegate.m
3+
// CodingForiPad
4+
//
5+
// Created by sunguanglei on 15/6/8.
6+
// Copyright (c) 2015年 coding. All rights reserved.
7+
//
8+
9+
#import "AppDelegate.h"
10+
#import "COStyleFactory.h"
11+
#import "COSession.h"
12+
#import <KVOController/FBKVOController.h>
13+
#import <AFNetworkActivityLogger.h>
14+
#import "SDWebImageManager.h"
15+
#import "EaseStartView.h"
16+
#import "XGPush.h"
17+
#import "CORootViewController+Notification.h"
18+
19+
#define degreesToRadian(x) (M_PI * (x) / 180.0)
20+
21+
@interface AppDelegate ()
22+
23+
@end
24+
25+
@implementation AppDelegate
26+
27+
#pragma mark XGPush
28+
- (void)registerPushForIOS8{
29+
UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
30+
UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert
31+
categories:[NSSet setWithObject:categorys]];
32+
[[UIApplication sharedApplication] registerUserNotificationSettings:userSettings];
33+
[[UIApplication sharedApplication] registerForRemoteNotifications];
34+
}
35+
36+
- (void)registerPush{
37+
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
38+
}
39+
40+
- (void)xgRegPush
41+
{
42+
void (^successCallback)(void) = ^(void){
43+
//如果变成需要注册状态
44+
if(![XGPush isUnRegisterStatus])
45+
{
46+
//iOS8注册push方法
47+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
48+
49+
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
50+
if(sysVer < 8){
51+
[self registerPush];
52+
}
53+
else{
54+
[self registerPushForIOS8];
55+
}
56+
#else
57+
//iOS8之前注册push方法
58+
//注册Push服务,注册后才能收到推送
59+
[self registerPush];
60+
#endif
61+
}
62+
};
63+
[XGPush initForReregister:successCallback];
64+
}
65+
66+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
67+
{
68+
[XGPush startApp:kXGPushId appKey:kXGPushKey];
69+
//sd加载的数据类型
70+
[[[SDWebImageManager sharedManager] imageDownloader] setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
71+
72+
// Override point for customization after application launch.
73+
[COStyleFactory applyStyle];
74+
[self observeUserStatus];
75+
76+
#ifdef DEBUG
77+
[[AFNetworkActivityLogger sharedLogger] startLogging];
78+
#endif
79+
80+
EaseStartView *startView = [EaseStartView startView];
81+
__weak typeof(self) weakself = self;
82+
[startView startAnimationWithCompletionBlock:^(EaseStartView *easeStartView) {
83+
//[[UIApplication sharedApplication] setStatusBarHidden:NO];
84+
[weakself completionStartAnimationWithOptions:launchOptions];
85+
}];
86+
return YES;
87+
}
88+
89+
- (void)completionStartAnimationWithOptions:(NSDictionary *)launchOptions{
90+
if ([COSession session].userStatus == COSessionUserStatusLogined) {
91+
NSDictionary *remoteNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
92+
if (remoteNotification) {
93+
[[CORootViewController currentRoot] handleNotificationInfo:remoteNotification applicationState:UIApplicationStateInactive];
94+
}
95+
}
96+
97+
//推送反馈(app不在前台运行时,点击推送激活时。统计而已)
98+
[XGPush handleLaunching:launchOptions];
99+
}
100+
101+
- (void)observeUserStatus
102+
{
103+
[self.KVOController observe:[COSession session] keyPath:@"userStatus" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew block:^(id observer, COSession *object, NSDictionary *change) {
104+
if (object.userStatus == COSessionUserStatusDefault
105+
|| object.userStatus == COSessionUserStatusLogout) {
106+
[XGPush setAccount:nil];
107+
[XGPush unRegisterDevice];
108+
UIStoryboard *login = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
109+
self.window.rootViewController = [login instantiateInitialViewController];
110+
[self.window makeKeyAndVisible];
111+
}
112+
else if (object.userStatus == COSessionUserStatusLogined) {
113+
NSLog(@"%@", object.user.globalKey);
114+
[XGPush setAccount:object.user.globalKey];
115+
[self xgRegPush];
116+
UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
117+
self.window.rootViewController = [main instantiateInitialViewController];
118+
[self.window makeKeyAndVisible];
119+
}
120+
}];
121+
}
122+
123+
- (void)applicationWillResignActive:(UIApplication *)application {
124+
// 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.
125+
// 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.
126+
}
127+
128+
- (void)applicationDidEnterBackground:(UIApplication *)application {
129+
// 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.
130+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
131+
}
132+
133+
- (void)applicationWillEnterForeground:(UIApplication *)application {
134+
// 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.
135+
}
136+
137+
- (void)applicationDidBecomeActive:(UIApplication *)application {
138+
// 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.
139+
}
140+
141+
- (void)applicationWillTerminate:(UIApplication *)application {
142+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
143+
}
144+
145+
#pragma mark -
146+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
147+
{
148+
NSString * deviceTokenStr = [XGPush registerDevice:deviceToken successCallback:^{
149+
// NSLog(@"success");
150+
} errorCallback:^{
151+
// NSLog(@"error");
152+
}];
153+
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:deviceTokenStr delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
154+
// [alert show];
155+
#ifdef DEBUG
156+
NSLog(@"deviceTokenStr : %@", deviceTokenStr);
157+
#endif
158+
}
159+
160+
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
161+
{
162+
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:error.description delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
163+
// [alert show];
164+
}
165+
166+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
167+
{
168+
#ifdef DEBUG
169+
NSLog(@"didReceiveRemoteNotification-userInfo:-----\n%@", userInfo);
170+
#endif
171+
[XGPush handleReceiveNotification:userInfo];
172+
[[CORootViewController currentRoot] handleNotificationInfo:userInfo applicationState:[application applicationState]];
173+
}
174+
175+
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
176+
return UIInterfaceOrientationMaskAll;
177+
}
178+
179+
@end

0 commit comments

Comments
 (0)