Je veux faire une application qui fait de la demande HTTP à un site Web périodiquement. L'application doit fonctionner en arrière-plan, mais peut se réveiller ou montrer une notification, en fonction d'une réponse de la demande. Comme un message de WhatsApp, mais je n'ai pas de serveur Web, seul le périphérique vérifie les valeurs de la demande HTTP GET. P>
3 Réponses :
Le seul moyen de faire est à l'aide d'une notification push silencieuse (voir le docs < fort> ici strong> et ici strong> ), il réveillera votre application sur fond et vous donnera une chance d'exécuter du code pendant un peu de temps. Mais malheureusement, il ne fonctionnera pas avec la notification locale, doit être une notification push. P>
Votre application a 30 secondes pour effectuer toutes les tâches et appeler le gestionnaire d'achèvement fourni p>
blockQuote>
Et si vous envoyez trop de poussée, l'iOS peut punir votre application en lui donnant une petite priorité d'exécuter votre tâche, ou même simplement ne l'exécutant pas p>
Merci de répondre.Oncece je vais vérifier, marquer comme réponse correcte
Si vous utilisez une notification push silencieuse, vous devez savoir que la pousse silencieuse doit avoir une limite pour l'envoi de fréquence. P>
vérifier pour voir si des notifications silencieuses sont étrangères. APNS envoie un nombre limité de notifications silencieuses-notifications avec le Contenu clés disponible - par jour. De plus, si l'appareil a déjà dépassé son budget d'alimentation pour la journée, les notifications silencieuses ne sont pas envoyé à nouveau jusqu'à ce que le budget de puissance réinitialise, ce qui se passe une fois par jour. Ces limites sont désactivées lors du test de votre application de Xcode. P> blockQuote>
et ne pas faire appel à l'application si la force de l'application - quitte. p>
Si vous avez besoin de livraison garantie, vous devez utiliser la notification Push VoIP. Mais vous avez besoin de raison pour Apple, pourquoi vous avez besoin d'une poussée VoIP. P>
mais vous êtes bien drainez la batterie sans arrêt, et ce n'est pas amical pour vos utilisateurs. strong> p>
Il est possible d'utiliser des notifications push silencieux, vous pouvez cette réponse.
import Firebase import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var dataManager = DataManager() var reloadSign = false; let gcmMessageIDKey = "gcm.message_id" func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Fabric.with([Crashlytics.self]) // Override point for customization after application launch. IQKeyboardManager.shared.enable = true DropDown.startListeningToKeyboard() FirebaseApp.configure() Messaging.messaging().delegate = self UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] // //Solicit permission from user to receive notifications UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (_, error) in guard error == nil else{ print(error!.localizedDescription) return } } // // //get application instance ID InstanceID.instanceID().instanceID { (result, error) in if let error = error { print("Error fetching remote instance ID: \(error)") } else if let result = result { print("Remote instance ID token: \(result.token)") } } application.registerForRemoteNotifications() return true } func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { if let messageID = userInfo[gcmMessageIDKey] { print("Message ID: \(messageID)") let proj = Project() proj.checkData() } // Print full message. print(userInfo) } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print("Unable to register for remote notifications: \(error.localizedDescription)") } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. let ud = UserDefaults.standard ud.set( true, forKey: "isTerminated"); ud.synchronize() } func crashlyticsDidDetectReport(forLastExecution report: CLSReport, completionHandler: @escaping (Bool) -> Void) { completionHandler(true) } } extension AppDelegate: UNUserNotificationCenterDelegate{ func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo // With swizzling disabled you must let Messaging know about the message, for Analytics // Messaging.messaging().appDidReceiveMessage(userInfo) // Print message ID. if let messageID = userInfo[gcmMessageIDKey] { print("Message ID: \(messageID)") } // Print full message. print(userInfo) // Change this to your preferred presentation option completionHandler([]) } func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo // Print message ID. if let messageID = userInfo[gcmMessageIDKey] { print("Message ID: \(messageID)") } // Print full message. print(userInfo) completionHandler() } } extension AppDelegate: MessagingDelegate{ func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) { print("Firebase registration token: \(fcmToken)") let dataDict:[String: String] = ["token": fcmToken] NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict) // TODO: If necessary send token to application server. // Note: This callback is fired at each app startup and whenever a new token is generated. } func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) { print("Received data message: \(remoteMessage.appData)") } }
Cela ne répond pas à rien qui est posé sur la question, ce n'est qu'un appdelegate avec la configuration FCM et d'autres configurations aléatoires. On dirait que vous ne copiez et collez votre fichier entier ici, sans aucune explication.
Vous ne pouvez pas. iOS ne supporte pas ce genre de planification de fond. Vous devriez avoir votre serveur envoyer une notification push. Il est beaucoup plus efficace en termes de batterie et de réseau que de sondages, même si vous pouviez le faire
@ Paulw11 Oky, merci de répondre, chacun envoyer des données au serveur, sa notification locale est possible ??, je peux m'envoyer un exemple d'exemple GitHub
Oui, vous pouvez utiliser les mises à jour de localisation. Votre application est-elle destinée à l'App Store? Si tel est le cas et que vous n'avez pas de besoin légitime d'emplacement, il sera rejeté. À l'aide des mises à jour de localisation en permanence une impact gravement sur la durée de vie de la batterie.
Il est possible, vérifiez cela, cela peut vous aider.