修改超时时间

This commit is contained in:
xsean 2025-11-11 14:32:45 +08:00
parent bebdfa0794
commit edcb876dec
26 changed files with 2235 additions and 2177 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -6,5 +6,5 @@ Author: XYZShell
Section: Utilities Section: Utilities
Tag: role::developer Tag: role::developer
Architecture: iphoneos-arm Architecture: iphoneos-arm
Version: 0.0.7-10-68+debug Version: 0.0.7-10-70+debug
Installed-Size: 1624 Installed-Size: 1624

View File

@ -1 +1 @@
./packages/com.xyzshell.ioscontrol_0.0.7-10-68+debug_iphoneos-arm.deb ./packages/com.xyzshell.ioscontrol_0.0.7-10-70+debug_iphoneos-arm.deb

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
68 70

View File

@ -136,7 +136,8 @@
*/ */
//self.status = [[XSConsole sharedInstance] status]; //self.status = [[XSConsole sharedInstance] status];
//self.appId = [[XSJsGlobalContext sharedInstance] get:@"ad_appid"]; //self.appId = [[XSJsGlobalContext sharedInstance] get:@"ad_appid"];
@synchronized (self) {
dispatch_async(self->_workQueue, ^{
if ([self.status isEqualToString:@"运行中"]) { if ([self.status isEqualToString:@"运行中"]) {
self->lastStop = [NSDate date]; self->lastStop = [NSDate date];
} }
@ -146,18 +147,18 @@
NSTimeInterval elapsed = [curRunTime timeIntervalSinceDate:self->lastStop]; NSTimeInterval elapsed = [curRunTime timeIntervalSinceDate:self->lastStop];
if (elapsed > 60 * 10 && !myadTaskManualStop) { if (elapsed > 60 * 10 && !myadTaskManualStop) {
self->lastStop = [NSDate date]; self->lastStop = [NSDate date];
dispatch_async(_workQueue, ^{ dispatch_async(self->_workQueue, ^{
[[MyAdTask2Mangger sharedInstance] start]; [[MyAdTask2Mangger sharedInstance] start];
}); });
} }
} });
self.name = self->iphone.IPhoneName; self.name = self->iphone.IPhoneName;
self.deviceId = self->iphone.DeviceId; self.deviceId = self->iphone.DeviceId;
self.ip = [[XSPhoneInfo sharedInstance] IPAddress]; self.ip = [[XSPhoneInfo sharedInstance] IPAddress];
self.remoteIp = [[XSPhoneInfo sharedInstance] remoteIp]; self.remoteIp = [[XSPhoneInfo sharedInstance] remoteIp];
self.diskSize = [[XSPhoneInfo sharedInstance] IPhoneStatus]; self.diskSize = [[XSPhoneInfo sharedInstance] IPhoneStatus];
self.message = @"251106-nt"; self.message = @"251110-nt";
// //
NSDictionary *heartbeatData = [self constructHeartbeatData]; NSDictionary *heartbeatData = [self constructHeartbeatData];
if (!heartbeatData) { if (!heartbeatData) {

View File

@ -29,8 +29,11 @@ BOOL myadTaskManualStop = NO;
NSString *dataId; NSString *dataId;
NSString *remoteIp; NSString *remoteIp;
NSString *country; NSString *country;
} }
@property (nonatomic, assign) NSTimeInterval lastAppSwitchTime; //
@end @end
@implementation MyAdTask2Mangger @implementation MyAdTask2Mangger
@ -55,6 +58,7 @@ BOOL myadTaskManualStop = NO;
self->screen_w = device_screen_width; self->screen_w = device_screen_width;
self->screen_h = device_screen_height; self->screen_h = device_screen_height;
self->adAfter = 1000; self->adAfter = 1000;
self.lastAppSwitchTime = 0; // 0
return self; return self;
} }
return nil; return nil;
@ -250,17 +254,20 @@ BOOL myadTaskManualStop = NO;
[[IPhoneHertbeat sharedInstance] setStatus:@"运行中"]; [[IPhoneHertbeat sharedInstance] setStatus:@"运行中"];
[self startApp]; [self startApp];
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
// Timer
if (!_timer) { if (_timer) {
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self.manQueue); dispatch_source_cancel(_timer);
dispatch_source_set_timer(_timer, dispatch_time(DISPATCH_TIME_NOW, 0), 10 * NSEC_PER_SEC, 1 * NSEC_PER_SEC); _timer = nil;
dispatch_source_set_event_handler(_timer, ^{
@autoreleasepool {
[weakSelf proc];
}
});
dispatch_resume(_timer);
} }
// 使 dispatch_source timer
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self.manQueue);
dispatch_source_set_timer(_timer, dispatch_time(DISPATCH_TIME_NOW, 0), 10 * NSEC_PER_SEC, 1 * NSEC_PER_SEC);
dispatch_source_set_event_handler(_timer, ^{
@autoreleasepool {
[weakSelf proc];
}
});
dispatch_resume(_timer);
[[MyEventBus sharedInstance] postEvent:@"UpdateRunStatus" withObject:@(YES)]; [[MyEventBus sharedInstance] postEvent:@"UpdateRunStatus" withObject:@(YES)];
} }
@ -273,21 +280,25 @@ BOOL myadTaskManualStop = NO;
NSDate* curRunTime = [NSDate date]; NSDate* curRunTime = [NSDate date];
NSTimeInterval elapsed = [curRunTime timeIntervalSinceDate:self->lastRun]; NSTimeInterval elapsed = [curRunTime timeIntervalSinceDate:self->lastRun];
if (elapsed >= 100) { if (elapsed >= 30) {
//[self onStop];
[self start]; [self start];
} else { } else {
NSString* appId = [self frontMostAppId]; NSString* appId = [ self frontMostAppId];
if (![appId isEqual: self->taskAppId]) {
//
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
if (currentTime - self.lastAppSwitchTime < 30) { // 30
NSLog(@"XS- App switching throttled. Last switch was %.0f seconds ago.", currentTime - self.lastAppSwitchTime);
return;
}
if (![appId isEqual:self->taskAppId]) {
[self appKill:appId]; [self appKill:appId];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), self.manQueue, ^{
// : strong使 [self appRun:self->taskAppId];
__weak typeof(self) weakSelf = self; self.lastAppSwitchTime = [NSDate timeIntervalSinceReferenceDate]; //
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), self.manQueue, ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) return;
[strongSelf appRun:strongSelf->taskAppId];
}); });
} }
} }
@ -476,9 +487,7 @@ BOOL myadTaskManualStop = NO;
if (strongSelf->taskAppId && ![strongSelf->taskAppId isEqual:[NSNull null]] && [strongSelf->taskAppId length] > 0) { if (strongSelf->taskAppId && ![strongSelf->taskAppId isEqual:[NSNull null]] && [strongSelf->taskAppId length] > 0) {
[weakSelf appKill:strongSelf->taskAppId]; [weakSelf appKill:strongSelf->taskAppId];
[weakSelf unlock]; [weakSelf unlock];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), strongSelf.manQueue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC),
strongSelf.manQueue, ^{
[weakSelf unlock]; [weakSelf unlock];
[weakSelf resetApp:strongSelf->taskAppId callback:callback]; [weakSelf resetApp:strongSelf->taskAppId callback:callback];
}); });
@ -517,41 +526,40 @@ BOOL myadTaskManualStop = NO;
- (void)touchAppTask:(int)beforeTouch { - (void)touchAppTask:(int)beforeTouch {
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
double delaySec = beforeTouch; if (beforeTouch > 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(beforeTouch * NSEC_PER_SEC)), self.manQueue, ^{
[self rndTouchApp];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), self.manQueue, ^{
int x = [XSHelper random:40 and:screen_w - 20];
int y = [XSHelper random:50 and:screen_h - 240];
[self tap:1 x:x y:y];
void (^touchBlock)(void) = ^{ NSString* appId = [ self frontMostAppId];
[weakSelf rndTouchApp]; if (![appId isEqual: self->taskAppId]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), self.manQueue, ^{
[self appRun:self->taskAppId];
});
} else {
[self appRun:self->taskAppId];
}
});
});
} else {
[self rndTouchApp];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), self.manQueue, ^{
int x = [XSHelper random:40 and:screen_w - 20];
int y = [XSHelper random:50 and:screen_h - 240];
[self tap:1 x:x y:y];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), NSString* appId = [ self frontMostAppId];
weakSelf.manQueue, ^{ if (![appId isEqual: self->taskAppId]) {
__strong typeof(weakSelf) strongSelf = weakSelf; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), self.manQueue, ^{
if (!strongSelf) return; [self appRun:self->taskAppId];
int x = [XSHelper random:40 and:strongSelf->screen_w - 20];
int y = [XSHelper random:50 and:strongSelf->screen_h - 240];
[strongSelf tap:1 x:x y:y];
NSString* appId = [strongSelf frontMostAppId];
if (![appId isEqual:strongSelf->taskAppId]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC),
strongSelf.manQueue, ^{
__strong typeof(weakSelf) strongSelf2 = weakSelf;
if (!strongSelf2) return;
[strongSelf2 appRun:strongSelf2->taskAppId];
}); });
} else { } else {
[strongSelf appRun:strongSelf->taskAppId]; [self appRun:self->taskAppId];
} }
}); });
};
if (delaySec > 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delaySec * NSEC_PER_SEC)),
self.manQueue, touchBlock);
} else {
touchBlock();
} }
} }

View File

@ -55,14 +55,10 @@ void startSimpleServer(void) {
// [server startServer]; // [server startServer];
XUDPServer *udpserver = [XUDPServer sharedInstance]; XUDPServer *udpserver = [XUDPServer sharedInstance];
[udpserver start]; [udpserver start];
// // NSRunLoopGCDAsyncUdpSocket
NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; // NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
// [runLoop addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
// // [runLoop run];
[runLoop addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
//
[runLoop run];
} }
}); });
}); });

View File

@ -18,11 +18,15 @@ typedef void (^rt_str_callback)(NSString*);
// @property (nonatomic, strong) NSURLSession *session; // @property (nonatomic, strong) NSURLSession *session;
@property (nonatomic, strong) NSURLSessionDataTask *dataTask; @property (nonatomic, strong) NSURLSessionDataTask *dataTask;
@property (nonatomic, strong) NSURLSessionDataTask *postDataTask; @property (nonatomic, strong) NSURLSessionDataTask *postDataTask;
@property (nonatomic, assign) NSTimeInterval timeoutInterval; // 新增超时属性
- (void) doGET: (NSString*) urlStr withCallback:(request_callback) callback withError: (error_callback) errorCallback; - (void) doGET: (NSString*) urlStr withCallback:(request_callback) callback withError: (error_callback) errorCallback;
- (NSData *) doGET: (NSString*) urlStr; - (NSData *) doGET: (NSString*) urlStr;
- (void) doPOST: (NSString*) urlStr json: (NSString *)json withCallback:(request_callback) callback withError: (error_callback) errorCallback; - (void) doPOST: (NSString*) urlStr json: (NSString *)json withCallback:(request_callback) callback withError: (error_callback) errorCallback;
- (NSData*) doPOST:(NSString *)urlStr json:(NSString *)json; - (NSData*) doPOST:(NSString *)urlStr json:(NSString *)json;
- (void)cancelAllRequests; // 新增取消所有请求方法
- (void)cancelCurrentGETRequest; // 新增取消当前GET请求方法
- (void)cancelCurrentPOSTRequest; // 新增取消当前POST请求方法
- (void)requestNetworkPermissions; - (void)requestNetworkPermissions;
@end @end

View File

@ -44,6 +44,7 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
@interface XSHttpHelper () { @interface XSHttpHelper () {
@private NSString *apikey; @private NSString *apikey;
@private NSURLSession *_session; // session
} }
@ -55,6 +56,12 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
-(instancetype)init { -(instancetype)init {
if (self = [super init]) { if (self = [super init]) {
apikey = [[XSPhoneConfig sharedInstance] ApiKey]; apikey = [[XSPhoneConfig sharedInstance] ApiKey];
self.timeoutInterval = 15.0; // 15
// NSURLSession
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.timeoutIntervalForRequest = self.timeoutInterval;
configuration.timeoutIntervalForResource = self.timeoutInterval;
self->_session = [NSURLSession sessionWithConfiguration:configuration delegate:[[SSLBypassDelegate alloc] init] delegateQueue:nil];
return self; return self;
} }
return nil; return nil;
@ -69,12 +76,12 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
NSURL *url = [NSURL URLWithString:urlStr]; NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5]; cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:self.timeoutInterval];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:self->apikey forHTTPHeaderField:@"apikey"]; [request setValue:self->apikey forHTTPHeaderField:@"apikey"];
NSURLSession *session = [NSURLSession sessionWithoutSSLValidation];// [NSURLSession sharedSession]; // 使session
self.dataTask = [session dataTaskWithRequest:request self.dataTask = [self->_session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{ {
NSLog(@"XS- http get res"); NSLog(@"XS- http get res");
@ -92,7 +99,6 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
NSLog(@"XS- http get exception error,%@", exception); NSLog(@"XS- http get exception error,%@", exception);
errorCallback(XSErrorFromException(exception)); errorCallback(XSErrorFromException(exception));
} }
} }
- (NSData *) doGET: (NSString*) urlStr { - (NSData *) doGET: (NSString*) urlStr {
@ -104,10 +110,10 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
} withError:^(NSError *err) { } withError:^(NSError *err) {
dispatch_semaphore_signal(semaphore); dispatch_semaphore_signal(semaphore);
}]; }];
// 5 // self.timeoutInterval
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC); dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.timeoutInterval * NSEC_PER_SEC));
// 5 //
long result = dispatch_semaphore_wait(semaphore, timeout); long result = dispatch_semaphore_wait(semaphore, timeout);
if (result == 0) { if (result == 0) {
@ -116,6 +122,8 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
} else { } else {
// //
NSLog(@"doGET 等待超时"); NSLog(@"doGET 等待超时");
//
[self.dataTask cancel];
} }
return _data; return _data;
} }
@ -124,7 +132,8 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
@try { @try {
NSLog(@"XS- doPOST:%@", urlStr); NSLog(@"XS- doPOST:%@", urlStr);
NSURL *url = [NSURL URLWithString:urlStr]; NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:self.timeoutInterval]; //
[request setHTTPMethod:@"POST"]; [request setHTTPMethod:@"POST"];
// //
@ -135,9 +144,8 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
NSData *bodyData = [XSHelper str2Data:json]; NSData *bodyData = [XSHelper str2Data:json];
[request setHTTPBody:bodyData]; [request setHTTPBody:bodyData];
NSURLSession *session = [NSURLSession sessionWithoutSSLValidation];//[NSURLSession sharedSession]; // 使session
self.postDataTask = [self->_session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
self.postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) { if (error) {
NSLog(@"XS- post error : %@", error); NSLog(@"XS- post error : %@", error);
errorCallback(error); errorCallback(error);
@ -163,10 +171,10 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
} withError:^(NSError *err) { } withError:^(NSError *err) {
dispatch_semaphore_signal(semaphore); dispatch_semaphore_signal(semaphore);
}]; }];
// 5 // self.timeoutInterval
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC); dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.timeoutInterval * NSEC_PER_SEC));
// 5 //
long result = dispatch_semaphore_wait(semaphore, timeout); long result = dispatch_semaphore_wait(semaphore, timeout);
if (result == 0) { if (result == 0) {
@ -175,6 +183,8 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
} else { } else {
// //
NSLog(@"do POST 等待超时"); NSLog(@"do POST 等待超时");
//
[self.postDataTask cancel];
} }
return _data; return _data;
} }
@ -203,4 +213,21 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
}]; }];
} }
- (void)cancelAllRequests {
[self.dataTask cancel];
[self.postDataTask cancel];
self.dataTask = nil;
self.postDataTask = nil;
}
- (void)cancelCurrentGETRequest {
[self.dataTask cancel];
self.dataTask = nil;
}
- (void)cancelCurrentPOSTRequest {
[self.postDataTask cancel];
self.postDataTask = nil;
}
@end @end

View File

@ -492,7 +492,7 @@
- (void)scheduleRestart { - (void)scheduleRestart {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)),
serverQueue, ^{ self->serverQueue, ^{ // serverQueue
[self start]; [self start];
}); });
} }

22
ips.txt
View File

@ -1,10 +1,12 @@
192.168.1.15 172.29.120.31
192.168.1.19 172.29.120.21
192.168.1.18 172.29.120.28
192.168.1.20 172.29.108.11
192.168.1.11 172.29.108.19
192.168.1.21 172.29.108.23
192.168.1.14 172.29.102.18
192.168.1.16 172.29.120.24
192.168.1.13 172.29.108.21
192.168.1.17 172.29.120.27
172.29.108.30
172.29.108.29

BIN
packages/20251110-nt.deb Normal file

Binary file not shown.