繁体   English   中英

iOS:后台处理完成时显示通知

[英]iOS : Present a notification when the background treatment is finished

我想向用户显示在应用程序结束后台处理时显示的通知。

这是我目前使用的代码:

UILocalNotification* localNotification = [[UILocalNotification alloc]init];
localNotification.alertBody = @"Your uploads are finished";
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];

但这是行不通的,当我调用endBackgroundTask时,看不到该通知。 但是,我使用了断点,并执行了此代码。

   //identify the application state you through the Local notification
   UIApplicationState state = [[UIApplication sharedApplication] applicationState];

 if (state==UIApplicationStateInactive)
  {
                    //Show the notification as text voice
                    UILocalNotification *notification = [[UILocalNotification alloc]init];
                    [notification setAlertBody:"title"];
                    notification.soundName = UILocalNotificationDefaultSoundName;
                    notification.alertAction = @"View";
                    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
                }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM