Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Today Extension using App Groups #44

Merged
merged 9 commits into from
Oct 31, 2015
Merged

Today Extension using App Groups #44

merged 9 commits into from
Oct 31, 2015

Conversation

arthurhammer
Copy link
Contributor

#33 introduced a basic widget. I've been looking into a full widget. Since this required quite a bit of more work, I made this a new PR.

alt text

UI and functions are simple but it's a good base to work from. I've been running this for a few days and it's quite stable.

Main Changes

App Groups

Extension and host app live in separate processes. They can only talk by using App Groups. Changing to app groups requires a bit of work:

  • Enabling App Group Capability for both host and extension.
  • Adding a group identifier, usually group.<main bundle ID>.

Problem: As with the main bundle ID, it seems we can’t share a group ID. Everyone has their own. The best I came up with:

  • Adding a project setting APP_GROUP_IDENTIFIER for everybody to set their group ID.
  • In code, getting the identifier from the Info.plist.
NSUserDefaults
  • To share defaults, now use [[NSUserDefaults alloc] initWithSuiteName:<group ID>] instead of standardUserDefaults. I added a category so we can just call [NSUserDefaults groupDefaults].
  • Call [defaults synchronize] when making changes.
  • It seems NSUserDefaultsDidChangeNotification won't get delivered between widget and app.
GammaController

App and widget have their own GammaController class which write to their own gammatable.dat file. This leads to the problem where the widget initializes its file with already modified gamma data instead of the default screen values (or vice versa). It will then use this wrong data as the base level for adjustments.

I changed it to write the gammatable.dat into the shared app group space. Works for now but is not protected against concurrent writes. Although it's unlikely widget and app will write at the same time, this should be resolved. Maybe there is a better solution altogether that does not clutter GammaController with app group related stuff.

Problem

The group ID stuff increases the barrier to entry for users who just want to install the thing. You now have to: (see linked screenshots)

I'm open for contributions and happy to change stuff as needed.

See also #14, #33.

@arthurhammer arthurhammer changed the title Today extension Today Extension using App Groups Oct 29, 2015
@ANGOmarcello
Copy link
Contributor

Nice work!
I can take a look into the not working NSUserDefaultsDidChangeNotification. I all ready did that in an other project.

Am 29.10.2015 um 14:17 schrieb Arthur Hammer notifications@github.com:

#14 #14 introduced a basic widget. I've been looking into a full widget. Since this required quite a bit of more work, I made this a new PR.

https://cloud.githubusercontent.com/assets/4521216/10815766/6f029fba-7e2e-11e5-9281-4186fc4e66bb.jpg
UI and functions are simple but it's a good base to work from. I've been running this for a few days and it's quite stable.

Main Changes

App Groups

Extension and host app live in separate processes. They can only talk by using App Groups http://www.atomicbird.com/blog/sharing-with-app-extensions. Changing to app groups requires a bit of work:

Enabling App Group Capability for both host and extension.
Adding a group identifier, usually group.

.
Problem: As with the main bundle ID, it seems we can’t share a group ID. Everyone has their own. The best I came up with:

Adding a project setting APP_GROUP_IDENTIFIER for everybody to set their group ID.
In code, getting the identifier from the Info.plist.
NSUserDefaults

To share defaults, now use [[NSUserDefaults alloc] initWithSuiteName:] instead of standardUserDefaults. I added a category so we can just call [NSUserDefaults groupDefaults].
Call [defaults synchronize] when making changes.
It seems NSUserDefaultsDidChangeNotification won't get delivered between widget and app http://stackoverflow.com/questions/28284989/nsuserdefaultsdidchangenotification-and-today-extensions.
GammaController

App and widget have their own GammaController class which write to their own gammatable.dat file. This leads to the problem where the widget initializes its file with already modified gamma data instead of the default screen values (or vice versa). It will then use this wrong data as the base level for adjustments.

I changed it to write the gammatable.dat into the shared app group space. Works for now but is not protected against concurrent writes. Although it's unlikely widget and app will write at the same time, this should be resolved. Maybe there is a better solution altogether that does not clutter GammaController with app group related stuff.

Problem

The group ID stuff increases the barrier to entry for users who just want to install the thing. You now have to: (see linked screenshots)

Add custom bundle ID to the main app (as before) https://cloud.githubusercontent.com/assets/4521216/10819152/d94683ce-7e46-11e5-9472-17a2ac69dc0a.png
Add custom bundle ID to the extension https://cloud.githubusercontent.com/assets/4521216/10819167/e688ef40-7e46-11e5-896f-7147794e5680.png
Create a group ID, add it to both main app https://cloud.githubusercontent.com/assets/4521216/10819192/ff74ff76-7e46-11e5-8ee6-a5bb1f6d39b1.png and extension https://cloud.githubusercontent.com/assets/4521216/10819204/0b2be370-7e47-11e5-8093-2947e89d6bce.png
Insert the group ID into the project setting https://cloud.githubusercontent.com/assets/4521216/10819210/1cf99e76-7e47-11e5-87ca-9647843ee745.png
I'm open for contributions and happy to change stuff as needed.

See also #14 #14, #33 #33.

You can view, comment on, or merge this pull request online at:

#44 #44
Commit Summary

Add Widget Target
Add App Groups
Switch NSUserDefaults to app group defaults
Synchronize shared defaults
Add widget controller logic
Add widget UI
Move registerDefaults to shared defaults plist
Cleanup
Share gammatable.dat between widget and host
File Changes

M GammaTest.xcodeproj/project.pbxproj https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-0 (230)
M GammaTest/AppDelegate.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-1 (25)
A GammaTest/Defaults.plist https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-2 (30)
A GammaTest/GammaTest.entitlements https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-3 (10)
M GammaTest/Info.plist https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-4 (10)
M GammaTest/MainViewController.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-5 (76)
A GammaTest/extentions/NSUserDefaults+Group.h https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-6 (19)
A GammaTest/extentions/NSUserDefaults+Group.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-7 (18)
M GammaTest/mvc/controller/GammaController.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-8 (29)
A GammaWidget/Base.lproj/MainInterface.storyboard https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-9 (157)
A GammaWidget/GammaWidget.entitlements https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-10 (10)
A GammaWidget/Info.plist https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-11 (35)
A GammaWidget/TodayViewController.h https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-12 (13)
A GammaWidget/TodayViewController.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-13 (117)
Patch Links:

https://github.com/thomasfinch/GammaThingy/pull/44.patch https://github.com/thomasfinch/GammaThingy/pull/44.patch
https://github.com/thomasfinch/GammaThingy/pull/44.diff https://github.com/thomasfinch/GammaThingy/pull/44.diff

Reply to this email directly or view it on GitHub #44.

@arthurhammer
Copy link
Contributor Author

Absolutely, that would be great.

On 29.10.2015, at 14:43, Ango notifications@github.com wrote:

Nice work!
I can take a look into the not working NSUserDefaultsDidChangeNotification. I all ready did that in an other project.

Am 29.10.2015 um 14:17 schrieb Arthur Hammer notifications@github.com:

#14 #14 introduced a basic widget. I've been looking into a full widget. Since this required quite a bit of more work, I made this a new PR.

https://cloud.githubusercontent.com/assets/4521216/10815766/6f029fba-7e2e-11e5-9281-4186fc4e66bb.jpg
UI and functions are simple but it's a good base to work from. I've been running this for a few days and it's quite stable.

Main Changes

App Groups

Extension and host app live in separate processes. They can only talk by using App Groups http://www.atomicbird.com/blog/sharing-with-app-extensions. Changing to app groups requires a bit of work:

Enabling App Group Capability for both host and extension.
Adding a group identifier, usually group.

.
Problem: As with the main bundle ID, it seems we can’t share a group ID. Everyone has their own. The best I came up with:

Adding a project setting APP_GROUP_IDENTIFIER for everybody to set their group ID.
In code, getting the identifier from the Info.plist.
NSUserDefaults

To share defaults, now use [[NSUserDefaults alloc] initWithSuiteName:] instead of standardUserDefaults. I added a category so we can just call [NSUserDefaults groupDefaults].
Call [defaults synchronize] when making changes.
It seems NSUserDefaultsDidChangeNotification won't get delivered between widget and app http://stackoverflow.com/questions/28284989/nsuserdefaultsdidchangenotification-and-today-extensions.
GammaController

App and widget have their own GammaController class which write to their own gammatable.dat file. This leads to the problem where the widget initializes its file with already modified gamma data instead of the default screen values (or vice versa). It will then use this wrong data as the base level for adjustments.

I changed it to write the gammatable.dat into the shared app group space. Works for now but is not protected against concurrent writes. Although it's unlikely widget and app will write at the same time, this should be resolved. Maybe there is a better solution altogether that does not clutter GammaController with app group related stuff.

Problem

The group ID stuff increases the barrier to entry for users who just want to install the thing. You now have to: (see linked screenshots)

Add custom bundle ID to the main app (as before) https://cloud.githubusercontent.com/assets/4521216/10819152/d94683ce-7e46-11e5-9472-17a2ac69dc0a.png
Add custom bundle ID to the extension https://cloud.githubusercontent.com/assets/4521216/10819167/e688ef40-7e46-11e5-896f-7147794e5680.png
Create a group ID, add it to both main app https://cloud.githubusercontent.com/assets/4521216/10819192/ff74ff76-7e46-11e5-8ee6-a5bb1f6d39b1.png and extension https://cloud.githubusercontent.com/assets/4521216/10819204/0b2be370-7e47-11e5-8093-2947e89d6bce.png
Insert the group ID into the project setting https://cloud.githubusercontent.com/assets/4521216/10819210/1cf99e76-7e47-11e5-87ca-9647843ee745.png
I'm open for contributions and happy to change stuff as needed.

See also #14 #14, #33 #33.

You can view, comment on, or merge this pull request online at:

#44 #44
Commit Summary

Add Widget Target
Add App Groups
Switch NSUserDefaults to app group defaults
Synchronize shared defaults
Add widget controller logic
Add widget UI
Move registerDefaults to shared defaults plist
Cleanup
Share gammatable.dat between widget and host
File Changes

M GammaTest.xcodeproj/project.pbxproj https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-0 (230)
M GammaTest/AppDelegate.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-1 (25)
A GammaTest/Defaults.plist https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-2 (30)
A GammaTest/GammaTest.entitlements https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-3 (10)
M GammaTest/Info.plist https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-4 (10)
M GammaTest/MainViewController.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-5 (76)
A GammaTest/extentions/NSUserDefaults+Group.h https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-6 (19)
A GammaTest/extentions/NSUserDefaults+Group.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-7 (18)
M GammaTest/mvc/controller/GammaController.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-8 (29)
A GammaWidget/Base.lproj/MainInterface.storyboard https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-9 (157)
A GammaWidget/GammaWidget.entitlements https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-10 (10)
A GammaWidget/Info.plist https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-11 (35)
A GammaWidget/TodayViewController.h https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-12 (13)
A GammaWidget/TodayViewController.m https://github.com/thomasfinch/GammaThingy/pull/44/files#diff-13 (117)
Patch Links:

https://github.com/thomasfinch/GammaThingy/pull/44.patch https://github.com/thomasfinch/GammaThingy/pull/44.patch
https://github.com/thomasfinch/GammaThingy/pull/44.diff https://github.com/thomasfinch/GammaThingy/pull/44.diff

Reply to this email directly or view it on GitHub #44.


Reply to this email directly or view it on GitHub.

@ylor
Copy link

ylor commented Oct 30, 2015

This is awesome. Well worth the extra steps to install, for me.

thomasfinch added a commit that referenced this pull request Oct 31, 2015
Today Extension using App Groups
@thomasfinch thomasfinch merged commit 373e3de into thomasfinch:master Oct 31, 2015
@fretn
Copy link

fretn commented Nov 9, 2015

nice work !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants