IOS:在后台收到本地通知时的调用方法 [英] IOS:Call method when local notification is received in background
问题描述
我知道这个问题看起来很重复,但是我没有找到符合我要求的确切答案.按照以下步骤进行与医疗事件相关的应用程序
I know this question looks duplicate but i did not found the exact answer as per my requirement.Doing app related to medical events with Below steps followed
1) connected the app to smart watch.
2) schedule the local notifications i. e when user needs to take
medicine
3) when the schedule time arrives local notification fires and
delegate method is calling (did receive local notification)
4) At the time of firing local notifications i am sending
message(sms) to the user from the app that he has to take certain
medicine
当应用程序处于前台状态且应用程序到达后台时,一切都工作正常,因为只有本地通知正在触发,用户未收到任何消息.因为当应用程序处于后台时,没有方法在调用,但是我的整个应用程序都在使用情况主要取决于发送短信.
Everything is working fine when the app is in foreground and when the app reaches to background only local notifications are firing no message is received by the user.Because no method is calling when the app is in background.But my whole application use case mostly depends on sending sms.
对此有什么解决方案吗?任何帮助都将受到欢迎! thnxx !!
Is there any solution for this ? Any help will be welcomed !! Thnxx !!
推荐答案
您将需要在UIBackgroundTask中显式运行您的方法.参见下面的示例:
You're going to need to explicitly run your method in a UIBackgroundTask. See example below:
UIApplication * application = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier background_task;
background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];
// your method call here
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
我正在做类似的事情,这对我有用.让我知道这是否对您不起作用.
I'm doing something similar and this works for me. Let me know if thats not working for you.
这篇关于IOS:在后台收到本地通知时的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!