Skip to content

Commit ee71589

Browse files
committed
私信
1 parent 7a8210a commit ee71589

5 files changed

Lines changed: 44 additions & 30 deletions

File tree

Coding_iOS/AppDelegate.m

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ - (void)completionStartAnimationWithOptions:(NSDictionary *)launchOptions{
8686
if ([Login isLogin]) {
8787
NSDictionary *remoteNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
8888
if (remoteNotification) {
89-
[BaseViewController handleNotificationInfo:remoteNotification];
89+
[BaseViewController handleNotificationInfo:remoteNotification applicationState:UIApplicationStateInactive];
9090
}
9191
}
9292

@@ -162,16 +162,8 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio
162162
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
163163
{
164164
NSLog(@"didReceiveRemoteNotification-userInfo:-----\n%@", userInfo);
165-
166-
if ([application applicationState] == UIApplicationStateInactive) {
167-
//If the application state was inactive, this means the user pressed an action button
168-
// from a notification.
169-
[XGPush handleReceiveNotification:userInfo];
170-
171-
[BaseViewController handleNotificationInfo:userInfo];
172-
}else if ([application applicationState] == UIApplicationStateActive){
173-
[[UnReadManager shareManager] updateUnRead];
174-
}
165+
[XGPush handleReceiveNotification:userInfo];
166+
[BaseViewController handleNotificationInfo:userInfo applicationState:[application applicationState]];
175167
}
176168

177169
#pragma mark - Methods Private

Coding_iOS/Controllers/ConversationViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
@interface ConversationViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, UITextViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, QBImagePickerControllerDelegate, UIMessageInputViewDelegate>
1515
@property (strong, nonatomic) PrivateMessages *myPriMsgs;
16+
- (void)refreshLoadMore:(BOOL)willLoadMore;
1617
@end

Coding_iOS/Controllers/ConversationViewController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ - (void)messageInputView:(UIMessageInputView *)inputView heightToBottomChenged:(
134134

135135
#pragma mark refresh
136136
- (void)refreshLoadMore:(BOOL)willLoadMore{
137-
138-
if (_myPriMsgs.isLoading) {
137+
if (!_myPriMsgs || _myPriMsgs.isLoading) {
139138
return;
140139
}
141140
_myPriMsgs.willLoadMore = willLoadMore;

Coding_iOS/Controllers/RootControllers/BaseViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- (void)tabBarItemClicked;
1414
- (void)loginOutToLoginVC;
1515

16-
+ (void)handleNotificationInfo:(NSDictionary *)userInfo;
16+
+ (void)handleNotificationInfo:(NSDictionary *)userInfo applicationState:(UIApplicationState)applicationState;
1717
+ (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr;
1818
+ (UIViewController *)presentingVC;
1919
@end

Coding_iOS/Controllers/RootControllers/BaseViewController.m

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#import "AppDelegate.h"
2222
#import "WebViewController.h"
2323

24+
#import "UnReadManager.h"
25+
2426
@interface BaseViewController ()
2527

2628
@end
@@ -84,24 +86,44 @@ - (void)forceChangeToOrientation:(UIInterfaceOrientation)interfaceOrientation{
8486
}
8587

8688
#pragma mark Notification
87-
+ (void)handleNotificationInfo:(NSDictionary *)userInfo{
88-
//标记为已读
89-
NSString *notification_id = [userInfo objectForKey:@"notification_id"];
90-
if (notification_id) {
91-
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTip:notification_id andBlock:^(id data, NSError *error) {
92-
if (error) {
93-
NSLog(@"request_markReadWithCodingTip: %@", error.description);
94-
}else{
95-
NSLog(@"request_markReadWithCodingTip: %@", data);
89+
+ (void)handleNotificationInfo:(NSDictionary *)userInfo applicationState:(UIApplicationState)applicationState{
90+
91+
92+
if (applicationState == UIApplicationStateInactive) {
93+
//If the application state was inactive, this means the user pressed an action button from a notification.
94+
//标记为已读
95+
NSString *notification_id = [userInfo objectForKey:@"notification_id"];
96+
if (notification_id) {
97+
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTip:notification_id andBlock:^(id data, NSError *error) {
98+
if (error) {
99+
NSLog(@"request_markReadWithCodingTip: %@", error.description);
100+
}else{
101+
NSLog(@"request_markReadWithCodingTip: %@", data);
102+
}
103+
}];
104+
}
105+
//弹出临时会话
106+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
107+
NSLog(@"handleNotificationInfo : %@", userInfo);
108+
NSString *param_url = [userInfo objectForKey:@"param_url"];
109+
[self presentLinkStr:param_url];
110+
});
111+
}else if (applicationState == UIApplicationStateActive){
112+
//处理私信
113+
NSString *param_url = [userInfo objectForKey:@"param_url"];
114+
NSString *conversionRegexStr = @"/user/messages/history/([^/]+)$";
115+
NSArray *matchedCaptures = [param_url captureComponentsMatchedByRegex:conversionRegexStr];
116+
if (matchedCaptures.count >0 && [[BaseViewController presentingVC] isKindOfClass:[ConversationViewController class]]) {
117+
NSString *user_global_key = [matchedCaptures lastObject];
118+
ConversationViewController *vc = (ConversationViewController *)[BaseViewController presentingVC];
119+
if ([vc.myPriMsgs.curFriend.global_key isEqualToString:user_global_key]) {
120+
[vc refreshLoadMore:NO];
121+
return;
96122
}
97-
}];
123+
}
124+
//标记未读
125+
[[UnReadManager shareManager] updateUnRead];
98126
}
99-
//弹出临时会话
100-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
101-
NSLog(@"handleNotificationInfo : %@", userInfo);
102-
NSString *param_url = [userInfo objectForKey:@"param_url"];
103-
[self presentLinkStr:param_url];
104-
});
105127
}
106128
+ (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr{
107129
NSLog(@"\n analyseVCFromLinkStr : %@", linkStr);

0 commit comments

Comments
 (0)