-->

IOS:当本地通知在后台接到电话的方法(IOS:Call method when local not

2019-10-22 16:14发布

我知道这个问题看起来重复的,但我并没有找到确切的答案,因为按我的requirement.Doing应用有关通过下面的步骤遵循医疗事件

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

一切工作正常时,应用程序在前台当应用达到背景只有本地通知被烧成由user.Because没有收到任何消息,没有方法调用时,应用程序是在background.But我的整个应用程序的使用情况主要取决于在发送短信。

对此有任何解决方案? 任何帮助将受到欢迎! Thnxx!

Answer 1:

你将需要显式地运行在UIBackgroundTask方法。 见下面例子:

    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;

我在做类似的事情,这对我的作品。 让我知道,如果不适合你的工作,多数民众赞成。



文章来源: IOS:Call method when local notification is received in background