LPPloveROU 2013-05-31 05:52 采纳率: 50%
浏览 1888

获取应用背景模式的本地通知

应用在背景模式下运行时如何获取本地通知?

谢谢

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate =[startDate addTimeInterval:60];
NSLog(@"%@",localNotif.fireDate);
localNotif.timeZone = [NSTimeZone defaultTimeZone];

localNotif.alertAction = @"View";

localNotif.soundName = UILocalNotificationDefaultSoundName;

NSString *notifStr=[NSString stringWithFormat:@"Hey looks like you're meeting up with %@, why don't you let your other friends know what fun they're missing out on? Share a photo :)",[itemDict objectForKey:@"fname"]];

NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:notifStr ,@"notifKey",nil];
localNotif.userInfo = infoDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
  • 写回答

1条回答

  • Chengzi_963 2013-05-31 09:09
    关注
    -(void)insert:(NSDate *)fire
    {
        [[UIApplication sharedApplication]cancelAllLocalNotifications];
        self.localNotification = [[UILocalNotification alloc] init];
        if (self.localNotification == nil)
        {
            return;
        }
        else
        {
            self.localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];
            self.localNotification.alertAction = nil;
            self.localNotification.soundName = UILocalNotificationDefaultSoundName;
            self.localNotification.alertBody = @"Hey looks like you're meeting up with %@, why don't you let your other friends know what fun they're missing out on? Share a photo :)";
            self.localNotification.alertAction = NSLocalizedString(@"Read Msg", nil);
            self.localNotification.applicationIconBadgeNumber=1;
            self.localNotification.repeatInterval=0;
            [[UIApplication sharedApplication] scheduleLocalNotification:self.localNotification];
        }
    }
    
    - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
    {
        [[UIApplication sharedApplication]cancelAllLocalNotifications];
        app.applicationIconBadgeNumber = notif.applicationIconBadgeNumber -1;
    
        notif.soundName = UILocalNotificationDefaultSoundName;
    
        [self _showAlert:[NSString stringWithFormat:@"%@",Your msg withTitle:@"Title"];
    
    }
    
    - (void) _showAlert:(NSString*)pushmessage withTitle:(NSString*)title
    {
        [self.alertView_local removeFromSuperview];
        self.alertView_local = [[UIAlertView alloc] initWithTitle:title message:pushmessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [self.alertView_local show];
    
        if (self.alertView_local)
        {
        }
    }
    

    看看能不能实现

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用