قالب وردپرس درنا توس
Home / IOS Development / How do I attach a photo to a local alert? : iOS Programming

How do I attach a photo to a local alert? : iOS Programming



So I tried this code, but the picture doesn't seem to attack, does anyone know what I'm doing wrong?

I receive this error

Error Domain = UNErrorDomain Code = 100 "Invalid attachment file URL" UserInfo = {NSLocalizedDescription = Invalid attachment file URL}

  UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter] UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter] UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter] ;

UNMutableNotificationContent * contentFor3Days = [[UNMutableNotificationContent alloc] init];

contentFor3Days.title = [NSString localizedUserNotificationStringForKey:@"See what's trending on Figgle!😁" arguments:nil];
contentFor3Days.body = [NSString localizedUserNotificationStringForKey:str arguments:nil];
contentFor3Days.sound = [UNNotificationSound defaultSound];
contentFor3Days.categoryIdentifier = @ "newCategory";


NSURL * imageURL = [NSURL URLWithString:@"https://img.thedailybeast.com/image/upload/c_fill,h_200,w_200,x_0,y_0/v1
490733486/author/20170327-stern-marlow-author.jpg"]; NSError * error1; UNNotificationAttachment * icon = [UNNotificationAttachment attachmentWithIdentifier:@"image" URL:imageURL options:nil error:&error1]; if (error1) { NSLog (@ "error while saving image attachments in notification:% @", error1) } if (icon) { contentFor3Days.attachments = @ [icon]; } [center addNotificationRequest:requestFor3Days withCompletionHandler:nil];

Source link