объявление Код просил:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// You must invoke setMinimumBackgroundFetchInterval:.
[application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];
// default, iOS decides. seems between 5 and 15 minutes.
// you cannot go below that time.
/* ADC:
(You can also enable this support by including the UIBackgroundModes key with the fetch value in your app’s Info.plist file.) Enabling this mode is not a guarantee that the system will give your app any time to perform background fetches. The system must balance your app’s need to fetch content with the needs of other apps and the system itself. After assessing that information, the system gives time to apps when there are good opportunities to do so.
When a good opportunity arises, the system WAKES or LAUNCHES your app into the background and calls the app delegate’s application:performFetchWithCompletionHandler: method. Use that method to check for new content and initiate a download operation if content is available.
*/
// UIApplicationState state = application.applicationState;
NSString * s = [NSString stringWithFormat:@"background=%d (didFinishLaunchingWithOptions)", application.applicationState == UIApplicationStateBackground];
return YES;
}
перезванивают:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler
{
NSInteger n = application.applicationIconBadgeNumber;
application.applicationIconBadgeNumber = n+1;
// we invoke an sync method, so we should call handler AFTER getting answer...
BOOL isIpad = [self isIpad];
NSString * ID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString* msg = [NSString stringWithFormat: @"PFCH=%ld-ipad%d-%@", (long)n, isIpad, ID];
// call a method on my server to send me back a mail. I add an ID for every device I tested in a battery of iPhone/iPads.
[self getTime: msg];
// if ok...
completionHandler(UIBackgroundFetchResultNewData);
// or completionHandler(UIBackgroundFetchResultNoData);
// or completionHandler(UIBackgroundFetchResultFailed);
}
другой метод:
-(void) getTime:(NSString*)msg
{
NSString* urlS = [NSString stringWithFormat: @"https://www.ingconti.com/PFCH.php?msg=%@", msg];
NSURL * URL = [NSURL URLWithString: urlS];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString * s = [[NSString alloc]initWithData:data encoding: NSUTF8StringEncoding];
NSLog(@"%@", s);
}
];
[task resume];
}
-(BOOL)isIpad;
{
UIUserInterfaceIdiom deviceType = [[UIDevice currentDevice] userInterfaceIdiom];
if (deviceType == UIUserInterfaceIdiomPad)
return YES;
return NO;
}
я использовать сервер как мои устройства могут быть в состоянии покоя, и я хочу почта назад на моем mac.
PHP-код на сервере просто анализирует GET и отправляет мне письмо с идентификатором устройства, поэтому я могу анализировать результаты на своем mac.
Можете ли вы опубликовать код, который вы пишете, чтобы достичь этого? В моих тестах, в течение первого часа у меня частота, аналогичная вашей, но минус час, я не получаю больше звонков до трех или четырех часов. – OverMind
Вы пытались вызвать без связанных с сетью вещей? – hyouuu