我想向用户显示应用程序结束后台处理时显示的通知。
这是我目前使用的代码:
UILocalNotification* localNotification = [[UILocalNotification alloc]init];
localNotification.alertBody = @"Your uploads are finished";
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];
但它不起作用,当我调用endBackgroundTask时,我没有看到通知。 但是,我使用了断点,并执行了此代码。
答案 0 :(得分:0)
//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];
}