自定义本地通知在Objective-C
答
其实,如果你正在建立一个本地通知,你是在具有图像通知本身显示有兴趣,你不必与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];
}
然后当通知出现后,图像将显示在通知横幅的右侧,就像它对消息通知所做的一样。并且您不必跳过设置带类别标识符的内容扩展等的所有环节。
+0
其实我的要求是显示通知,如附图所示。 –
请放一些代码。所以,回答者可以知道你为此付出了哪些努力。 –
http://prntscr.com/g2ds2r 我能够创建像这样的本地通知...我想知道如何定制它的用户界面。 –
你可以在下面的教程中看到Swift代码。您需要为Objective-c进行管理。 https://code.tutsplus.com/tutorials/ios-10-creating-custom-notification-interfaces--cms-27251 –