Skip to content

Commit

Permalink
hooked up mecanism for update when notification received #91
Browse files Browse the repository at this point in the history
  • Loading branch information
roznet committed Apr 11, 2021
1 parent 442b5a4 commit 6231e6f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
21 changes: 19 additions & 2 deletions ConnectStats/src/GCAppDelegate+Swift.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#import "GCAppDelegate+Swift.h"
#import "ConnectStats-Swift.h"
#import "GCWebConnect+Requests.h"

@import UserNotifications;

#define GC_STARTING_FILE @"starting.log"
Expand Down Expand Up @@ -81,8 +83,23 @@ -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NS
}else{
RZLog(RZLogInfo,@"remote notification %@", userInfo);
}
application.applicationIconBadgeNumber = 1;
completionHandler(UIBackgroundFetchResultNewData);
//application.applicationIconBadgeNumber = 1;

self.web.notificationHandler = ^(gcWebNotification notification){
if( notification == gcWebNotificationError){
self.web.notificationHandler = nil;
completionHandler(UIBackgroundFetchResultFailed);
}
if( notification == gcWebNotificationEnd){
self.web.notificationHandler = nil;
completionHandler(UIBackgroundFetchResultNewData);
}
};

if( ! [self.web servicesBackgroundUpdate]){
self.web.notificationHandler = nil;
completionHandler(UIBackgroundFetchResultNoData);
}
}


Expand Down
1 change: 1 addition & 0 deletions ConnectStats/src/GCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
[self registerForPushNotifications];
[self remoteStatusCheck];

return YES;
}

Expand Down
3 changes: 3 additions & 0 deletions ConnectStats/src/GCWebConnect+Requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
/// Search all activities for all services
-(void)servicesSearchAllActivities;

/// Start background upgrade, return true if started, false if nothing was possible/required
-(BOOL)servicesBackgroundUpdate;

-(void)servicesResetLogin; // when profile switch
-(void)servicesLogin; // add necessary login requests

Expand Down
14 changes: 14 additions & 0 deletions ConnectStats/src/GCWebConnect+Requests.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ -(BOOL)downloadMissingActivityDetails:(NSUInteger)n{
return rv;
}

-(BOOL)servicesBackgroundUpdate{
BOOL rv = false;
if( [[GCAppGlobal profile] configGetBool:CONFIG_CONNECTSTATS_ENABLE defaultValue:NO] &&
[[GCAppGlobal profile] serviceCompletedFull:gcServiceConnectStats] &&
[[GCAppGlobal profile] serviceSuccess:gcServiceConnectStats] ){
// Run on main queue as it accesses a navigation Controller
dispatch_async(dispatch_get_main_queue(), ^(){
[self addRequest:[GCConnectStatsRequestSearch requestWithStart:0 mode:false andNavigationController:[GCAppGlobal currentNavigationController]]];
});
rv = true;
}

return rv;
}
-(void)servicesSearch:(BOOL)reloadAll{
if( ([[GCAppGlobal profile] configGetBool:CONFIG_CONNECTSTATS_ENABLE defaultValue:NO])){
// Run on main queue as it accesses a navigation Controller
Expand Down
9 changes: 9 additions & 0 deletions ConnectStats/src/GCWebConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger,gcWebNotification){
gcWebNotificationEnd,
gcWebNotificationError,
gcWebNotificationNext,
gcWebNotificationChange
};

typedef BOOL (^GCWebValidateNextSearch)( NSDate * _Nullable , NSUInteger );
typedef void (^GCWebNotificationHandler)( gcWebNotification);

extern NSString * GCWebStatusDescription(GCWebStatus status);
extern NSString * GCWebStatusShortDescription(GCWebStatus status);
Expand All @@ -41,6 +49,7 @@ extern NSString * GCWebStatusShortDescription(GCWebStatus status);
@property (nullable,nonatomic,retain) NSError * lastError;
@property (nullable,nonatomic,retain) dispatch_queue_t worker;
@property (nullable,copy) GCWebValidateNextSearch validateNextSearch;
@property (nullable,copy) GCWebNotificationHandler notificationHandler;



Expand Down
19 changes: 19 additions & 0 deletions ConnectStats/src/GCWebConnect.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ -(void)dealloc{
[_worker release];

[_validateNextSearch release];
[_notificationHandler release];

[super dealloc];
}
Expand Down Expand Up @@ -484,6 +485,9 @@ -(void)next{
[self executeCurrentRequest];

[self notifyForString:NOTIFY_NEXT safeTries:5];
if( self.notificationHandler ){
self.notificationHandler(gcWebNotificationNext);
}
}else{
if (_requests.count == 0) {
RZLog(RZLogInfo, @"end data=%@", [GCUnit formatBytes:[RZRemoteDownload totalDataUsage]]);
Expand All @@ -498,9 +502,17 @@ -(void)next{
self.started = false;
if (someError) {
[self notifyForString:NOTIFY_ERROR];
if( self.notificationHandler ){
self.notificationHandler(gcWebNotificationError);
}

[self clearDoneRequests];
}else{
[self notifyForString:NOTIFY_END];
if( self.notificationHandler ){
self.notificationHandler(gcWebNotificationEnd);
}

[self clearDoneRequests];
}
}
Expand Down Expand Up @@ -554,6 +566,10 @@ -(void)downloadFailed:(RZRemoteDownload*)connection{
}

[self notifyForString:NOTIFY_ERROR];
if( self.notificationHandler ){
self.notificationHandler(gcWebNotificationError);
}

}

-(void)downloadDataSuccessful:(RZRemoteDownload *)connection data:(NSData *)data{
Expand Down Expand Up @@ -615,6 +631,9 @@ -(NSString*)httpUserAgent{

-(void)processNewStage{
[self notifyForString:NOTIFY_CHANGE];
if( self.notificationHandler ){
self.notificationHandler(gcWebNotificationChange);
}
}

-(BOOL)checkState{
Expand Down

0 comments on commit 6231e6f

Please sign in to comment.