Forum Xamarin Xamarin.iOS

iOS 10 Local Notification Attachment Image from URL

edited November 2016 in Xamarin.iOS


In my app, I have a local notification that I want to grab an image from a URL (http://www....png). I know how to grab it from my local file system below, but don't know how to grab the image from an Image URL from the internet. How would one go about this? I have a sample below that grabs from my local file system, and would want to convert to grabbing an image URL from the internet. Any help would be appreciated. Thanks!

 public static void Sendlocalnotification()
        var localURL = "file:///" + NSBundle.MainBundle.PathForResource("RUN", "gif");
        NSUrl url = NSUrl.FromString(localURL) ;

        var attachmentID = "image";
        var options = new UNNotificationAttachmentOptions();
        NSError error;
        var attachment = UNNotificationAttachment.FromIdentifier(attachmentID, url, options,out error);

        var content = new UNMutableNotificationContent();
        content.Attachments = new UNNotificationAttachment[] { attachment };
        content.Title = "Good Morning ~";
        content.Subtitle = "Pull this notification ";
        content.Body = "reply some message-BY Ann";
        content.CategoryIdentifier = "message";

        var trigger1 = UNTimeIntervalNotificationTrigger.CreateTrigger(0.1, false);

        var requestID = "messageRequest";
        var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger1);

        UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =>
             if (err != null)
                 Console.Write("Notification Error");


Best Answer



    Thanks works great!

Sign In or Register to comment.