【问题标题】:Customize local notification in objective-c在objective-c中自定义本地通知
【发布时间】:2018-01-06 13:52:08
【问题描述】:

如何在objective-c中创建this type的本地通知。

【问题讨论】:

  • 请输入一些代码。因此,回答者可以知道您为此付出了哪些努力。
  • prntscr.com/g2ds2r 我可以像这样创建本地通知...我想知道如何自定义它的 UI。
  • 你可以在下面的教程中看到 Swift 代码。您需要为 Objective-c 管理它。 code.tutsplus.com/tutorials/…
  • 谢谢...我会检查的。

标签: ios objective-c unnotificationattachment


【解决方案1】:

实际上,如果您正在设置本地通知,并且您只想让图像显示在通知本身中,则不必为 NotificationsUI.framework 而烦恼

UNMutableNotificationContent *content = [UNMutableNotificationContent new];
    content.title = @"Title";
    content.body = @"Body";
    content.sound = [UNNotificationSound defaultSound];
    NSURL *imageURL = [NSURL URLWithString:@"file:/some/path/in/app/image.png"];
    NSError *error;
    UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"image" URL:imageURL options:nil error:&error];
    if (error)
    {
        NSLog(@"error while storing image attachment in notification: %@", error);
    }
    if (icon)
    {
        content.attachments = @[icon];
    }

然后,当通知出现时,图像将显示在通知横幅的右侧,就像消息通知一样。而且您不必费力地使用 categoryIdentifier 等设置内容扩展。

【讨论】:

  • 实际上我的要求是显示通知,如附图所示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多