【问题标题】:IOS:Call method when local notification is received in backgroundIOS:后台收到本地通知时调用方法
【发布时间】:2015-04-16 08:40:21
【问题描述】:

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

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

当应用程序在前台时一切正常,当应用程序到达后台时,只有本地通知正在触发,用户没有收到任何消息。因为当应用程序在后台时没有调用任何方法。但是我的整个应用程序使用情况主要取决于发送短信。

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

【问题讨论】:

    标签: objective-c iphone notifications uilocalnotification uibackgroundtask


    【解决方案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;
    

    我正在做类似的事情,这对我有用。如果这不适合你,请告诉我。

    【讨论】:

    • 您好,感谢您的回复,我怀疑在特定时间在后台触发本地通知时会调用任何委托方法
    • 会回答类似于这个精选的stackoverflow.com/questions/49857236/…
    • 我应该把这个方法放在didenterbackground
    • @XcodianSolangi 不会在本例中处理本地通知的代码中发生这种情况
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    • 2016-11-27
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多