修改超时时间

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
Tag: role::developer
Architecture: iphoneos-arm
Version: 0.0.7-10-68+debug
Version: 0.0.7-10-70+debug
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.appId = [[XSJsGlobalContext sharedInstance] get:@"ad_appid"];
@synchronized (self) {
dispatch_async(self->_workQueue, ^{
if ([self.status isEqualToString:@"运行中"]) {
self->lastStop = [NSDate date];
}
@ -146,18 +147,18 @@
NSTimeInterval elapsed = [curRunTime timeIntervalSinceDate:self->lastStop];
if (elapsed > 60 * 10 && !myadTaskManualStop) {
self->lastStop = [NSDate date];
dispatch_async(_workQueue, ^{
dispatch_async(self->_workQueue, ^{
[[MyAdTask2Mangger sharedInstance] start];
});
}
}
});
self.name = self->iphone.IPhoneName;
self.deviceId = self->iphone.DeviceId;
self.ip = [[XSPhoneInfo sharedInstance] IPAddress];
self.remoteIp = [[XSPhoneInfo sharedInstance] remoteIp];
self.diskSize = [[XSPhoneInfo sharedInstance] IPhoneStatus];
self.message = @"251106-nt";
self.message = @"251110-nt";
//
NSDictionary *heartbeatData = [self constructHeartbeatData];
if (!heartbeatData) {

View File

@ -29,8 +29,11 @@ BOOL myadTaskManualStop = NO;
NSString *dataId;
NSString *remoteIp;
NSString *country;
}
@property (nonatomic, assign) NSTimeInterval lastAppSwitchTime; //
@end
@implementation MyAdTask2Mangger
@ -55,6 +58,7 @@ BOOL myadTaskManualStop = NO;
self->screen_w = device_screen_width;
self->screen_h = device_screen_height;
self->adAfter = 1000;
self.lastAppSwitchTime = 0; // 0
return self;
}
return nil;
@ -250,17 +254,20 @@ BOOL myadTaskManualStop = NO;
[[IPhoneHertbeat sharedInstance] setStatus:@"运行中"];
[self startApp];
__weak typeof(self) weakSelf = self;
if (!_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);
// Timer
if (_timer) {
dispatch_source_cancel(_timer);
_timer = nil;
}
// 使 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)];
}
@ -273,21 +280,25 @@ BOOL myadTaskManualStop = NO;
NSDate* curRunTime = [NSDate date];
NSTimeInterval elapsed = [curRunTime timeIntervalSinceDate:self->lastRun];
if (elapsed >= 100) {
if (elapsed >= 30) {
//[self onStop];
[self start];
} else {
NSString* appId = [self frontMostAppId];
if (![appId isEqual:self->taskAppId]) {
} else {
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;
}
[self appKill:appId];
// : strong使
__weak typeof(self) weakSelf = self;
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];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), self.manQueue, ^{
[self appRun:self->taskAppId];
self.lastAppSwitchTime = [NSDate timeIntervalSinceReferenceDate]; //
});
}
}
@ -476,9 +487,7 @@ BOOL myadTaskManualStop = NO;
if (strongSelf->taskAppId && ![strongSelf->taskAppId isEqual:[NSNull null]] && [strongSelf->taskAppId length] > 0) {
[weakSelf appKill:strongSelf->taskAppId];
[weakSelf unlock];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC),
strongSelf.manQueue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), strongSelf.manQueue, ^{
[weakSelf unlock];
[weakSelf resetApp:strongSelf->taskAppId callback:callback];
});
@ -517,41 +526,40 @@ BOOL myadTaskManualStop = NO;
- (void)touchAppTask:(int)beforeTouch {
__weak typeof(self) weakSelf = self;
double delaySec = beforeTouch;
void (^touchBlock)(void) = ^{
[weakSelf rndTouchApp];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC),
weakSelf.manQueue, ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) return;
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];
NSString* appId = [ self frontMostAppId];
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];
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];
NSString* appId = [ self frontMostAppId];
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 {
[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];
XUDPServer *udpserver = [XUDPServer sharedInstance];
[udpserver start];
//
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
//
[runLoop addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
//
[runLoop run];
// NSRunLoopGCDAsyncUdpSocket
// NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
// [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) NSURLSessionDataTask *dataTask;
@property (nonatomic, strong) NSURLSessionDataTask *postDataTask;
@property (nonatomic, assign) NSTimeInterval timeoutInterval; // 新增超时属性
- (void) doGET: (NSString*) urlStr withCallback:(request_callback) callback withError: (error_callback) errorCallback;
- (NSData *) doGET: (NSString*) urlStr;
- (void) doPOST: (NSString*) urlStr json: (NSString *)json withCallback:(request_callback) callback withError: (error_callback) errorCallback;
- (NSData*) doPOST:(NSString *)urlStr json:(NSString *)json;
- (void)cancelAllRequests; // 新增取消所有请求方法
- (void)cancelCurrentGETRequest; // 新增取消当前GET请求方法
- (void)cancelCurrentPOSTRequest; // 新增取消当前POST请求方法
- (void)requestNetworkPermissions;
@end

View File

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

View File

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

22
ips.txt
View File

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

BIN
packages/20251110-nt.deb Normal file

Binary file not shown.