Question

I am attemping to write a weather notification center widget which works the way like system's Yahoo weather widget: tap the widget, open my own weather app, select a city and the widget show the weather of the city i chose. But I don't know how the widget can obtain the weather app's city setting. I use the *notification_center_widget*.nic to build my widget, which make it looks like a independent app running in bulletin board(Am i correct?).Now the weather app and widget both use archive to save city setting.

How does system's weather widget do that?

Can the weather app directly write file in weather widget's bundle? Or the weather widget directly read file in weather app?

I also tried to use openURL to pass selected cityname to the widget: add URL Schemes to Info.plist in Resources folder, and follow the UIApplicationDelegate protocol, implement the handleOpenURL function. but it dosen't work.

I tried to use presentModalViewController: to pop a citySelectViewController instead of set city in another app, but the viewcontroller only shows in the small area which the widget presents.

Thanks in advance.

Was it helpful?

Solution

I found a way seems a little like cheating to set widget's city in another app. I make the widget to archive city setting data in the root folder of the bundle(can be seen by iFile). Since the widget bundle will be installed into a specific folder. The weather app can use bundleWithPath to easily get the widget's bundle and archive city setting in the bundle when the user done selecting city. Then, when the widget runs again, it will read city setting data, which is already changed by the weather app, and show the weather of the city we chose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top