Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c IOS:在后台接收本地通知时调用方法_Objective C_Iphone_Notifications_Uilocalnotification_Uibackgroundtask - Fatal编程技术网

Objective c IOS:在后台接收本地通知时调用方法

Objective c IOS:在后台接收本地通知时调用方法,objective-c,iphone,notifications,uilocalnotification,uibackgroundtask,Objective C,Iphone,Notifications,Uilocalnotification,Uibackgroundtask,我知道这个问题看起来是重复的,但我没有按照我的要求找到确切的答案。按照以下步骤制作与医疗事件相关的应用程序 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

我知道这个问题看起来是重复的,但我没有按照我的要求找到确切的答案。按照以下步骤制作与医疗事件相关的应用程序

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
当应用程序在前台,当应用程序到达后台时,一切正常。只有本地通知触发,用户没有收到任何消息。因为应用程序在后台时没有方法调用。但我的整个应用程序用例主要依赖于发送短信


有什么解决办法吗?欢迎任何帮助!!Thnxx

您需要在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;

我也在做类似的事情,这对我很有用。如果这对您不起作用,请告诉我。

您好,谢谢您的回复,我怀疑在特定时间在后台触发本地通知时是否会调用任何委托方法。我是否应该将此方法放入
dienterbackground
@xciderisolangi中?不,这将发生在处理本例中的本地通知