Push Notifications with Service Extension Help

We have successfully implemented push notifications with the service extension on an iPhone 5; however, on iPhone 6 it's not working.
(https://developer.xamarin.com/guides/ios/platform_features/user-notifications/advanced-user-notifications/)

We can extract the image for attachment and display correctly on the iPhone 5; however on the iPhone 6 the image is null.

The only difference seems to be hardware the iPhone 6 has 3D Touch.
Does this hardware difference change how we need to handle the UNNotificationRequest request?

We are stumped why code is working on 1 device and not the other (running the same iOS, etc)...

Can anyone please provide any insight?

Here is our DidReceiveNotificationRequest method.

`public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action contentHandler)
{
ContentHandler = contentHandler;
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();

        try
        {
            if (BestAttemptContent.Body == "error")
            {
                throw new NotImplementedException("Error Test");
            }

            NSDictionary aps = request?.Content?.UserInfo?.ObjectForKey(new NSString("aps")) as NSDictionary;
            NSObject imageObject = aps?.ValueForKey(new NSString("imageurl"));
            String imageUrl = imageObject?.ToString();
            if (!String.IsNullOrEmpty(imageUrl))
            {
                NSError err = null;

                var url = new NSUrl(imageUrl);
                var task = NSUrlSession.SharedSession.CreateDownloadTask(new NSMutableUrlRequest(url), (tempfile, response, error) =>
                {

                    if (error != null)
                    {
                        BestAttemptContent.Title = "Download Task Error";
                        BestAttemptContent.Subtitle = url.ToString();
                        BestAttemptContent.Body = error.ToString();
                        ContentHandler(BestAttemptContent);
                        return;
                    }
                    if (tempfile == null)
                    {
                        BestAttemptContent.Title = "Temp File is NULL";
                        ContentHandler(BestAttemptContent);
                        return;
                    }

                    var cache = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User, true);
                    var cachesFolder = cache[0];
                    var guid = NSProcessInfo.ProcessInfo.GloballyUniqueString;
                    var fileName = guid + ".jpg";
                    var cacheFile = cachesFolder + "/" + fileName;
                    var attachmentURL = NSUrl.CreateFileUrl(cacheFile, false, null);

                    NSFileManager.DefaultManager.Move(tempfile, attachmentURL, out err);
                    if (err != null)
                    {
                        BestAttemptContent.Title = "File Move Error";
                        BestAttemptContent.Body = err.ToString();
                        ContentHandler(BestAttemptContent);
                        return;
                    }

                    // Create attachment;
                    var attachmentID = "image";
                    var options = new UNNotificationAttachmentOptions();
                    var attachment = UNNotificationAttachment.FromIdentifier(attachmentID, attachmentURL, options, out err);

                    BestAttemptContent.Attachments = new UNNotificationAttachment[] { attachment };


                    BestAttemptContent.Title = BestAttemptContent.Title;
                    BestAttemptContent.Body = BestAttemptContent.Body;
                    BestAttemptContent.CategoryIdentifier = BestAttemptContent.CategoryIdentifier;

                    //Display notification
                    ContentHandler(BestAttemptContent);
                });
                task.Resume();

            }
            else
            {
                BestAttemptContent.Body = BestAttemptContent.Body;
                ContentHandler(BestAttemptContent);
                return;
            }
        }
        catch (Exception ex)
        {
            BestAttemptContent.Title = "[E]" + BestAttemptContent.Title;
            BestAttemptContent.Subtitle = ex.Message;
            ContentHandler(BestAttemptContent);
            return;
        }
    }`
Sign In or Register to comment.