Post

Replies

Boosts

Views

Activity

Reply to Widget is crashing with 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=30 MB, unused=0x0)
yes you are right. Am saving the compressed quality image into userdefaults and loading the image with actual resolution from user defaults and while displaying resizing the image based on widget like 61x61 and 46x46. As per your suggestion now I am saving the image with 200x200 into user defaults and getting the same while displaying it as 46X46 for medium and 61x61 for large into widgets and. But still am getting memory limit exception while rendering the both medium( has two articles with images) and large family widgets (4 articles with images). Working fine when rendering the data for medium widget ( with two articles and two images). Note: Both the widgets has same data but no of records vary. Any suggestions on this.
Sep ’22
Reply to Widget is crashing with 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=30 MB, unused=0x0)
Saving images from timeline provider into UserDefaults by compressing the quality and calling the getImageFromUserDefaults bind the image which was saved.  //Get the images from the User Defaults based on resId.     static func getImageFromUserDefaults(key: String) -> UIImage? {         if let userDefaults = UserDefaults(suiteName: userDefaultsAppGroup) {             if let imageData = userDefaults.object(forKey: key) as? Data,                let image = UIImage(data: imageData) {                 return image             }         }                  return nil     }          //Save the images into User Defaults, reId as Key     static func saveIntoUserDefaults(image : UIImage, resId: Int) {         if let userDefaults = UserDefaults(suiteName: SharedContentConstants.userDefaultsAppGroup) {             if let jpegRepresentation = image.jpegData(compressionQuality: 0.5) {                     userDefaults.set(jpegRepresentation, forKey: String(resId))                 }         }     }
Sep ’22
Reply to Widget is not auto refreshing
As you suggested I have added only two timeline entries but still the widget is not getting auto refreshed.     func getTimeline(in context: Context, completion: @escaping (Timeline<RecommendedWidgetEntry>) -> Void) {         let accessTokenValue = Keychain.getAccessTokenValue()         if let token = accessTokenValue, !token.isEmpty  {                widgetVM.getRecommendedDataForWidget{ (result) in                     switch result {                     case .success(let items):                         widgetVM.downloadImages(recommendedData: items) { (result) in                             switch result {                             case .success(_),.failure(_) :                                 var refreshEntries: [RecommendedWidgetEntry] = []                                 if let At6AM = Calendar.current.date(bySettingHour: 6, minute: 0, second: 0, of: Date()) {                                     let refreshEntryFor6AM = RecommendedWidgetEntry(date: At6AM, recommedationData: items)                                     refreshEntries.append(refreshEntryFor6AM)                                 }                                 if let At6PM = Calendar.current.date(bySettingHour: 18, minute: 0, second: 0, of: Date()) {                                     let refreshEntryFor6PM = RecommendedWidgetEntry(date: At6PM, recommedationData: items)                                     refreshEntries.append(refreshEntryFor6PM)                                 }                                 let timeline = Timeline(entries: refreshEntries, policy: .atEnd)                                 completion(timeline)                             }                         }                     case .failure(_):                         let entry = RecommendedWidgetEntry(date: Date(), recommedationData: WidgetFeedModel.getPlaceholderData())                             let timeline = Timeline(entries: [entry], policy: .never)                             completion(timeline)                     }                 }         }         else {             if accessTokenValue == nil { // if token is nil then considering it as member is not logged in.                 SharedContentConstants.clearUserDefaultsData()                 let entry = RecommendedWidgetEntry(date: Date(), recommedationData: [])                 let timeline = Timeline(entries: [entry], policy: .never)                 completion(timeline)                 return             }         }     } On my timeline provider am calling the Rest API to fetch the data to update the widget. Could you please help me out is there any issue with the refresh policy ( My widgets must auto refresh twice a day like 6AM and 6PM) Kindly provide the reason, why the widgets are not autorefreshing on it's own. Thanks.
Sep ’22
Reply to Widget is crashing with 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=30 MB, unused=0x0)
Am downloading the images like this and binding to widget UI. Correct me how can I proceed these memory limit issue. struct NetworkImage: View {          let url: URL?     var viewDimension : CGFloat = 46          var body: some View {             if let url = url, let imageData = try? Data(contentsOf: url),                let uiImage = UIImage(data: imageData) {                 AnyView( Image(uiImage: uiImage)                     .resizable()                     .aspectRatio(1, contentMode: .fit)                     .frame(width: viewDimension, height: viewDimension, alignment: .center)                     .border(Color(red: 0.957, green: 0.957, blue: 0.957), width: 2.0)                     .cornerRadius(4)                 )             }             else {                                  AnyView( EmptyView() )             }     } }
Sep ’22