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

Support for iOS 11 #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ extern "C" void *WiFiDeviceClientCopyCurrentNetwork(void *);

@interface UIImage ()
+ (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
@end

@interface WPScanRequest : NSObject
- (void)setRssiThreshold:(NSNumber *)arg1;
@end
2 changes: 1 addition & 1 deletion Resources/WiPi.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>© 2013 - 2017 Bensge and contributors</string>
<string>© 2013 - 2018 Bensge and contributors</string>
</dict>
</array>
<key>title</key>
Expand Down
96 changes: 92 additions & 4 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define CoreFoundationiOS7 847.20
#define CoreFoundationiOS10 1348.00
#define CoreFoundationiOS11 1443.00

static BOOL shouldShowPicker = NO;

Expand Down Expand Up @@ -88,8 +89,8 @@ static BOOL isLongHoldEnabled()
return;
}

//It does not work well on lock screen on iOS10.
if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS10 && [[objc_getClass("SBUserAgent") sharedUserAgent] deviceIsLocked]) return;
//It does not work well on lock screen on iOS10 and iOS 11.
if (((kCFCoreFoundationVersionNumber >= CoreFoundationiOS10 && kCFCoreFoundationVersionNumber < CoreFoundationiOS11) && [[objc_getClass("SBUserAgent") sharedUserAgent] deviceIsLocked]) || (kCFCoreFoundationVersionNumber >= CoreFoundationiOS11 && [[objc_getClass("SBUserAgent") alloc] deviceIsLocked])) return;

if (event)
{
Expand Down Expand Up @@ -269,10 +270,13 @@ static BOOL isLongHoldEnabled()
- (void)scan
{
//Only on 7 and later
if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS7)
if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS7 && kCFCoreFoundationVersionNumber < CoreFoundationiOS11)
{
[[objc_getClass("WFWiFiManager") sharedInstance] setValue:[NSNumber numberWithInt:-130] forKey:@"_rssiThreshold"];
}
}
else if (kCFCoreFoundationVersionNumber >= CoreFoundationiOS11) {
[[objc_getClass("WPScanRequest") alloc] setRssiThreshold:[NSNumber numberWithInt:-130]];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method actually affect the wifi scan initiated by the system or does this only change this instance of WPScanRequest? I would assume the latter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no change on the normal Wi-Fi setting screen. Valid only when scanning with WiPi.

}
%orig;
}

Expand Down Expand Up @@ -490,6 +494,58 @@ static char wipiHoldGestureRecognizer;
%end
%end

@interface CCUIConnectivityWifiViewController : UIViewController
@property (nonatomic, retain) UILongPressGestureRecognizer *longPressRecognizer;
@property (nonatomic, retain) UIButton *button;
- (void)_wipi_longHoldAction;
@end

%group ControlCenter11
%hook CCUIConnectivityWifiViewController
%property (nonatomic, retain) UILongPressGestureRecognizer *longPressRecognizer;

%new
- (void)longPressRecognized:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
if ([self valueForKey:@"_parentViewController"]) {
if ([[self valueForKey:@"_parentViewController"] valueForKey:@"_expanded"]) {
if ([[[self valueForKey:@"_parentViewController"] valueForKey:@"_expanded"] boolValue] == YES) {
[self _wipi_longHoldAction];
}
}
}
}
}

- (id)init {
CCUIConnectivityWifiViewController *controller = %orig;
if (controller) {
controller.longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressRecognized:)];
controller.longPressRecognizer.minimumPressDuration = 0.9;
}
return controller;

}

- (void)viewDidLoad {
%orig;
if (self.longPressRecognizer && self.button) {
[self.button addGestureRecognizer:self.longPressRecognizer];
}
}

%new
- (void)_wipi_longHoldAction
{
if (isLongHoldEnabled())
{
[[LAActivator sharedInstance] sendEvent:nil toListenerWithName:@"com.bensge.wipi"];
}
}

%end
%end

/*
* Hook setup code
*/
Expand Down Expand Up @@ -568,6 +624,16 @@ void initFlipSwitch()
%end
%end

static BOOL didHook = NO;
static void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
if ([((__bridge NSDictionary *)userInfo)[NSLoadedClasses] containsObject:@"CCUIConnectivityAirDropViewController"]) { // The Network Bundle is Loaded
if (!didHook) {
didHook = YES;
%init(ControlCenter11);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the notification observer afterwards? Just to clean things up and not leave the notification listener active forever

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete it. It is necessary to prepare another method.

}
}
}

/*
* -------------
* | Constructor |
Expand All @@ -591,6 +657,28 @@ void initFlipSwitch()
%init(ControlCenter, BUTTONCLASS=(objc_getClass("SBControlCenterButton") ?: objc_getClass("CCUIControlCenterPushButton")));
}

BOOL shouldInit = NO;
if (!NSClassFromString(@"APTableCell")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the logic here? This is not obvious to me. Why do you load the AirPort Settings bundle, if it succeeds, wait for the network bundle to be loaded?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the notification method above, you need to prepare another method.

NSString *fullPath = [NSString stringWithFormat:@"/System/Library/PreferenceBundles/AirPortSettings.bundle"];
NSBundle *bundle;
bundle = [NSBundle bundleWithPath:fullPath];
BOOL didLoad = [bundle load];
if (didLoad) {
shouldInit = YES;
}
} else {
shouldInit = YES;
}

if (shouldInit && kCFCoreFoundationVersionNumber >= CoreFoundationiOS11)
{
CFNotificationCenterAddObserver(
CFNotificationCenterGetLocalCenter(), NULL,
notificationCallback,
(CFStringRef)NSBundleDidLoadNotification,
NULL, CFNotificationSuspensionBehaviorCoalesce);
}

loadSettings();
}
}
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.bensge.wipi
Name: WiPi
Depends: firmware (>= 6.0), libactivator, mobilesubstrate, preferenceloader
Version: 1.5.1
Version: 1.5.2
Architecture: iphoneos-arm
Description: Activate system WiFi Picker with an Activator gesture, or by long-pressing the Control Center or FlipSwitch WiFi toggle. Automatically enables Wi-Fi if not enabled.
Maintainer: bensge
Expand Down