This repository was archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Creating a Widget
Elijah Frederickson edited this page Jan 17, 2015
·
1 revision
Creating a widget for ReachApp is pretty simple, especially if you already have a view for in the Reachability section.
Here is outlined the steps for creating a widget and a few other little notes.
-
Build ReachApp and put the ReachApp headers into $THEOS/include/ReachApp
-
Create a new set of files, such as MyRAWidget.{h,mm} or (MyRAWidget.h and Tweak.xm)
-
The header file
In the MyRAWidget.h put something like this:
#import <UIKit/UIKit.h>
#import <ReachApp/RAWidget.h>
@interface MyRAWidget : RAWidget
@end
- In the MyRAWidget.mm you need to then create the implementation for your widget.
(3a. You may need to swap the
@implementation XXXfor%subclass XXXif you aren't linking with the ReachApp binary)
#import "RADefaultWidgetSection.h"
#import "MyRAWidget.h"
#import <dlfcn.h>
@implementation MyRAWidget : RAWidget
// OR: %subclass MyRAWidget : RAWidget
-(NSString*) identifier { return @"com.example_widget.thisneedstobeunique"; }
// actual view for showing in Reachability
-(UIView*) view
{
UILabel *sampleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
sampleView.text = @"Sample!";
return sampleView;
}
// Similar to an app icon with the image/title
-(UIView*) iconForSize:(CGSize)size
{
UIView *icon = [[UIView alloc] initWithFrame:(CGRect){ { 0, 0}, size }];
... create an image and/or some other icon thing (could be adapted from the preference bundle image)...
return icon;
}
@end
- Register the widget
In your constructor...
Tweak.xm: %ctor
MyRAWidget.mm: static __attribute__((constructor)) void __mytweak_init()
You need to load both ReachApp and the widget:
static id MyRAWidget$instance = nil;
%ctor
{
dlopen("/Library/MobileSubstrate/DynamicLibraries/ReachApp.dylib", RTLD_GLOBAL | RTLD_NOW);
MyRAWidget$instance = [[MyRAWidget alloc] init]; // If you used %subclass than use %c to get the class
[%c(RADefaultWidgetSection) sharedDefaultWidgetSection] registerWidget:MyRAWidget$instance];
}
Bonus things
Hmm... nothing yet...