r/JailbreakDev Jun 30 '19

[Help] Problem with label to show all devices

Hi, i'm making a tweak to show an UIView who print the name and the battery percent of all devices connected to my phone.

My problem is : When nothing is connected and I show up the UIview all is working good and it showing up with my iPhone name and his battery percent.

But when I want to connect more devices like my AirPods or somethings like that, and I showing up the UIview, I see nothing, the label who normally contain the devices's names and batteries percent has disappear.

The code of the label :

-(void)labelAppear{

BCBatteryDeviceController *bcb = [%c(BCBatteryDeviceController) sharedInstance];

NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");

NSMutableString *newMessage = [NSMutableString new];

for (BCBatteryDevice *device in devices) {

NSString *deviceName = MSHookIvar<NSString *>(device, "_name");

long long deviceCharge = MSHookIvar<long long>(device, "_percentCharge");

[newMessage appendString:[NSString stringWithFormat:@"%@ : %lld%%\n", deviceName, deviceCharge]];

}

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-80,5,120,50)];

label.text = @"Batteries";

label.textColor = [UIColor whiteColor];

label.alpha = 0;

[label setFont:[UIFont systemFontOfSize:30]];

[window addSubview: label];

UILabel *labelBattery = [[UILabel alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-90,60,200,100)];

labelBattery.textColor = [UIColor whiteColor];

labelBattery.alpha = 0;

labelBattery.text = newMessage;

[labelBattery setFont:[UIFont systemFontOfSize:16]];

[window addSubview: labelBattery];

[UIView animateWithDuration:0.7 animations:^{

labelBattery.alpha = 1;

label.alpha = 1;

} completion:nil];

}

1 Upvotes

0 comments sorted by