Hi all,
I've got a pretty simple app (basically a Hootsuite like and light).
I'd was hoping to create a widget that show the last post if it is today, or an view that encourages the user to create a new post.
To that purpose, I create a Codable model that I store in the shared UserDefaults (suiteName) and when I do so, I call the fefrshtimeline as follows :
func save() {
let encoder = JSONEncoder()
if let data = try? encoder.encode(self) {
UserDefaults.group.set(data, forKey: "lastPost")
WidgetCenter.shared.getCurrentConfigurations { (result) in
guard case .success(let widgets) = result else { return }
widgets.forEach { widget in
WidgetCenter.shared.reloadTimelines(ofKind: widget.kind)
}
}
}
}
The thing is, I put a print in the timeLine and it's never called. I also tried to change the snapShot method, nothing works so far.
Here are both methods from the Widget :
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
print("🏵 getSnapshot")
if let model = ExtensionSharedModel.retrieve(), model.date.isToday {
print("🏵 add model \(model.displayName)")
completion(SimpleEntry(date: Date(), model: model))
} else {
print("🏵 no models to add...")
completion(SimpleEntry(date: Date()))
}
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
print("🏵 getTimeline")
var entries: [SimpleEntry] = []
if let model = ExtensionSharedModel.retrieve(), model.date.isToday {
print("🏵 add model \(model.displayName)")
entries = [SimpleEntry(date: Date(), model: model)]
} else {
print("🏵 no models to add...")
entries = [SimpleEntry(date: Date())]
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
The widget is static configuration widget.
I do enter in WidgetCenter.shared.reloadTimelines, but never in the protocol methods.
Thanks for your help :-)
Post
Replies
Boosts
Views
Activity
Hi everyone
I'm struggling with this d*** FB SDK :-/
Basically, I've got an app that is supposed to post content to a FB Page. To achieve that, I login using the FB sdk. Then I request authorisations as follow
LoginManager().logIn(permissions: ["pages_manage_posts", "pages_read_engagement", "pages_show_list"], viewController: controller) { result in
										print("res \(result)")
										switch result {
										case .success:
												// the pageId is in data>id
												Defaults[\.facebookSwitchOn] = true
												GraphRequest.init(graphPath: "me/accounts").start { (connexion, result, error) in
														guard let result = result as? [String:Any],
																	let dataArray = result["data"] as? Array<Any>,
																	let data = dataArray.first as? [String:Any],
																	let pageId = data["id"] as? String,
																	let access = data["access_token"] as? String else { return }
														print("\(pageId)")
														Defaults[\.facebookPageId] = pageId
														Defaults[\.facebookPageAccessToken] = access
												}
												completion(true)
										case .failed(let error):
												completion(false)
												MessageManager.show(.basic(.custom(title: "Oups".local(), message: error.localizedDescription, buttonTitle: nil, configuration: MessageDisplayConfiguration.alert)), in: controller)
										default: ()
										}
								}
I save the pageId and TokenID to be able to perform a POST request as follow
GraphRequest
										.init(graphPath: "\(pageId)/photos",
//										parameters: ["source" : image, "caption" : text, "access_token" : token, "published" : false],
												parameters: ["caption" : contentDescription, "url" : "https://www.cdiscount.com/pdt2/9/2/8/1/700x700/889698377928/rw/figurine-funko-pop-deluxe-game-of-thrones-daen.jpg", "access_token" : token],
												httpMethod: .post)
										.start { (connexion, result, error) in
										completion(Result.success(true))
								}
However, I get a weird error telling that publish_actions has been deprecated.
I logged the request using Charles, and here it is
(https:// ibb.co/89wPgKx) (remove the space after the // )
Now here is the debug from the GraphAPI explorer :
curl -i -X POST \ "https://graph.facebook.com/v7.0/104226051340555/photos?caption=test%20message%20from%20Graph%20API%20for%20photo&url=https%3A%2F%2Fwww.cdiscount.com%2Fpdt2%2F9%2F2%2F8%2F1%2F700x700%2F889698377928%2Frw%2Ffigurine-funko-pop-deluxe-game-of-thrones-daen.jpg&access_token=<access token sanitized>"
Basically, it is the same request excepting the fact that parameters in the explorer are URL parameters and they are encapsulated in a json.
I can't understand why the graph explorer request succeeds while the SDK request fails.
I'm totally stuck :-/
Thanks for your help.
Hi,I've got annotations on a MKMapView and I added a custom view inside the detailCalloutAccessoryView. This custom view performs a request and should present various amount of data depending on the request's reply. Basically, I can show 1 or 2 rows of data.Sometimes, when I touch an annotation and the result is only one row, the callout is not resized. However, if I dimiss the annotation and select it once again, it is rendered correctly.What is the "right" way to make it work? Using a intrinsicContentSize, or calling layoutIfNeeded (already tried, did not work)Thanks for your help.