Objective-c でこのタイプのローカル通知を作成する方法。
1 に答える
0
実際、ローカル通知を設定していて、通知自体に画像を表示することに関心がある場合は、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 などを使用してコンテンツ拡張機能を設定するためのすべての手順を実行する必要はありません。
于 2017-07-31T06:07:45.600 に答える