M1 specific crash for "try UNNotificationAttachment(identifier: "image", url: fileURL)"

Originator:pranav
Number:rdar://FB10017548 Date Originated:13/05/22
Status:Open Resolved:
Product:Developer Tools Product Version:iOS 15
Classification:Error/Incorrect/Unexpected Behavior Reproducible:Always
 
I am having an issue with the UserNotifications framework only on M1 machines. The following function call crashes only on M1 but works fine for the same version of Xcode (13.2.1+) and iOS 15.2+:

`try UNNotificationAttachment(identifier: "image", url: fileURL)`

The full snippet is here:

```
private func attachment(for image: UIImage) -> UNNotificationAttachment? {
		guard let data = image.pngData() else {
			assertionFailure()
			return nil
		}
		
		let tempDirectory = URL(fileURLWithPath: NSTemporaryDirectory())
			.appendingPathComponent("titan_notification_request_images", isDirectory: true)
		
		do {
			try FileManager.default.createDirectory(at: tempDirectory,
													withIntermediateDirectories: true,
													attributes: nil)
			
			let uniqueFilename = "\(image.hashValue).png"
			let fileURL = tempDirectory.appendingPathComponent(uniqueFilename)
			try data.write(to: fileURL)
			
			return try UNNotificationAttachment(identifier: "image", url: fileURL)
		} catch let error {
			assertionFailure()
			return nil
		}
	}
```

I get the following error message:

“Unrecognized attachment file type”

The other lines above do not throw any errors. Hope you can advise, thanks!

Comments

  • the same version of Xcode (13.2.1+) and iOS 15.2+ on Intel Macs

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!