Terminate single or multiple applications outside the switcher iOS 7 tweak - iphone

I'm developing tweaks for jailbroken iphone, iOS 7, and I have a problem that I can't solve for a while,
is it possible to close all apps running in the background directly from Springboard without opening the background switcher panel?
All the tweaks and source codes I've seen, like Purge, Slide2Kill working from the app switcher panel using self for the controller.
I've tried the following ways:
SBAppSliderController* switcherController = MSHookIvar<SBAppSliderController*>(self, "_switcherController");
//or
SBUIController *sharedUI = [objc_getClass("SBUIController") sharedInstance];
SBAppSliderController * switcherController = [sharedUI _appSliderController];
//tried this:
SBAppSliderController * switcherController = [sharedUI _switcherController];
//and
SBAppSliderController * switcherController = MSHookIvar<SBAppSliderController *>(sharedUI, "_switcherController");
To quit all apps I need to call _quitAppAtIndex with all application index available
[switcherController _quitAppAtIndex:appIndex];
%hook SBAppSliderController
- (void)_quitAppAtIndex:(unsigned int)arg1
{
%log;
if (arg1 == 0) {
for (NSString *appID in [self applicationList]) {
if (![appID isEqualToString:#"com.apple.springboard"])
[self _quitAppAtIndex:[[self applicationList] indexOfObject:appID]];
}
}
else
%orig;
}
Every time I call the function I get the next error, even if I want to close only one app, and I call it with specific index:
: -[ _quitAppAtIndex:1]
: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSDictionaryM removeObjectForKey:]: key cannot be nil'
What I'm doing wrong? any help would be appreciated
Thank you.

You have to toggle switcher first, this code works for me:
static SBAppSliderController *_localSBAppSliderC = nil;
%hook SBAppSliderController
-(id)init {
%log;
id r = %orig;
_localSBAppSliderC = (SBAppSliderController *)r;
NSLog(#" = %#", r);
return r;
}
%end
-(void) KillAllApps {
SBUIController * SBUIC = [objc_getClass("SBUIController") sharedInstance];
[SBUIC _toggleSwitcher];
if (_localSBAppSliderC) {
NSLog(#"----------applist %#",[_localSBAppSliderC applicationList]);
for (NSString *identifier in [_localSBAppSliderC applicationList]) {
if ( ![identifier isEqualToString:#"com.apple.springboard"] )
{
int index = [[_localSBAppSliderC applicationList] indexOfObject:identifier];
NSLog(#"---_quitAppAtIndex: %d",index);
[_localSBAppSliderC _quitAppAtIndex:index];
}
}
[SBUIC dismissSwitcherAnimated:YES];
}

Related

How to check whether I am in the rootview of that viewcontroller in tabbaritem?

I have an iPhone application in which I am testing in the applicationDidBecomeActive: that if the selected viewcontroller's rootview is there, then I want to call one webservice, otherwise not when I am coming from background to foreground I am taking the stack and checking it. But now even if I am in the rootview the webservice is not getting called. Can anybody help me on this?
Here is my code snippet:
- (void)applicationDidBecomeActive:(UIApplication *)application{
NSLog(#"applicationWilssnd");
if(tabBarController.selectedIndex==0)
{
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(#"%#",mycontrollers);
///if([mycontrollers objectAtIndex:0]!=)
///[[mycontrollers objectAtIndex:0] popToRootViewControllerAnimated:NO];
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if([mycontrollers objectAtIndex:0]!=pinvc)
{
}
else
{
[pinvc merchantnews];
}
mycontrollers = nil;
tabBarController.selectedIndex = 0;
}
}
`here the merchantnews is not getting called.
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if([mycontrollers objectAtIndex:0]!=pinvc)
Instead of this, try this
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if(pinvc isKindOfClass:[PinBoardViewController class]){
// Do ur stuff
}

AVCaptureSession - Stop Running - take a long long time

I use ZXing for an app, this is mainly the same code than the ZXing original code except that I allow to scan several time in a row (ie., the ZXingWidgetController is not necesseraly dismissed as soon as something is detected).
I experience a long long freeze (sometimes it never ends) when I press the dismiss button that call
- (void)cancelled {
// if (!self.isStatusBarHidden) {
// [[UIApplication sharedApplication] setStatusBarHidden:NO];
// }
[self stopCapture];
wasCancelled = YES;
if (delegate != nil) {
[delegate zxingControllerDidCancel:self];
}
}
with
- (void)stopCapture {
decoding = NO;
#if HAS_AVFF
if([captureSession isRunning])[captureSession stopRunning];
AVCaptureInput* input = [captureSession.inputs objectAtIndex:0];
[captureSession removeInput:input];
AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[captureSession.outputs objectAtIndex:0];
[captureSession removeOutput:output];
[self.prevLayer removeFromSuperlayer];
/*
// heebee jeebees here ... is iOS still writing into the layer?
if (self.prevLayer) {
layer.session = nil;
AVCaptureVideoPreviewLayer* layer = prevLayer;
[self.prevLayer retain];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 12000000000), dispatch_get_main_queue(), ^{
[layer release];
});
}
*/
self.prevLayer = nil;
self.captureSession = nil;
#endif
}
(please notice that the dismissModalViewController that remove the view is within the delegate method)
I experience the freeze only while dismissing only if I made several scans in a row, and only with an iPhone 4 (no freeze with a 4S)
Any idea ?
Cheers
Rom
According to the AV Cam View Controller Example calling startRunning or stopRunning does not return until the session completes the requested operation. Since you are sending these messages to the session on the main thread, it freezes all the UI until the requested operation completes. What I would recommend is that you wrap your calls in an Asynchronous dispatch so that the view does not lock-up.
- (void)cancelled
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self stopCapture];
});
//You might want to think about putting the following in another method
//and calling it when the stop capture method finishes
wasCancelled = YES;
if (delegate != nil) {
[delegate zxingControllerDidCancel:self];
}
}

cocos2D automatic moving image

Everything looks fine, I have no errors, yet, when I run the program it crashes. Please help, I'm getting frustrated. Here's what I have:
-(id) init {
if( (self=[super init])) {
homeCloud1 = [CCSprite spriteWithFile:#"homeCloud1.png"];
homeCloud1.position = ccp(140,200);
[self addChild:homeCloud1];
[self schedule:#selector(callEveryFrame)];
}
return self;
}
-(void) callEveryFrame: (ccTime) dt {
homeCloud1.position = ccp(homeCloud1.position.x +20*dt, homeCloud1.position.y);
if (homeCloud1.position.x > 480+30) {
homeCloud1.position = ccp(-30, homeCloud1.position.y);
}
}
Cant say for sure, post your crash log but there is one error I see
[self schedule:#selector(callEveryFrame)];
needs a colon
[self schedule:#selector(callEveryFrame:)];

App Crashing When Calling Release on Autorelease Pool - Timing Issue ? iPhone

I have the following method in my app :
- (void) loadModel {
// Runs in a seperate thread so we need to create an additional NSAutoreleasePool
pool = [[NSAutoreleasePool alloc] init];
NSData *getData = [activeModelInfo getFileData];
if (getData) {
if ([activeModel loadFromFileData:daeData]) {
[activeModel reset];
[mainViewController performSelectorOnMainThread:#selector(showModelView) withObject:nil waitUntilDone:NO];
}
else {
}
}
else {
}
[pool release];
}
The loadFromFileData method calls the following code which loads data. :
- (void) loadVerticesFromSource:(NSString*)verticesSourceId meshNode:(TBXMLElement*)meshNode intoMesh: (Mesh3D*) mesh {
NSLog(#"Getting Vertices for Source %#",verticesSourceId);
FloatArray *floatArray = [self getFloatArrayFromSource: verticesSourceId meshNode: meshNode];
if (floatArray) {
[daeFloatArray addObject:floatArray];
}
if (floatArray) {
if ([floatArray.array count] % 3 != 0) {
NSLog(#"Float array length not divisible by 3!");
}
else {
mesh->verticesCount = [floatArray.array count] / 3;
mesh->vertices = malloc(sizeof(Vector3D) * mesh->verticesCount);
for (int i=0; i<mesh->verticesCount; i++) {
mesh->vertices[i].x = [[floatArray.array objectAtIndex:(i*3)] floatValue];
mesh->vertices[i].y = [[floatArray.array objectAtIndex:(i*3)+1] floatValue];
mesh->vertices[i].z = [[floatArray.array objectAtIndex:(i*3)+2] floatValue];
// update extents information
if (!extents.pointDefined || mesh->vertices[i].x < extents.minX) extents.minX = mesh->vertices[i].x;
else if (!extents.pointDefined || mesh->vertices[i].x > extents.maxX) extents.maxX = mesh->vertices[i].x;
if (!extents.pointDefined || mesh->vertices[i].y < extents.minY) extents.minY = mesh->vertices[i].y;
else if (!extents.pointDefined || mesh->vertices[i].y > extents.maxY) extents.maxY = mesh->vertices[i].y;
if (!extents.pointDefined || mesh->vertices[i].z < extents.minZ) extents.minZ = mesh->vertices[i].z;
else if (!extents.pointDefined || mesh->vertices[i].z > extents.maxZ) extents.maxZ = mesh->vertices[i].z;
if (!extents.pointDefined) extents.pointDefined = YES;
[pointerStorageArray addObject:[NSValue valueWithPointer:mesh->vertices]];
}
}
}
}
Since this method is called several times while the data loads, each time mallocing memory for the mesh->vertices struct, I have created a pointerStorage array where I store the pointer to the malloced memory.
The app then displays a 3D object using OpenGL ES. When the user presses a Main Menu button, I then free up the pointerStorageArray as follows :
- (void) freeUpMallocedMemory
for (NSValue * value in pointerStorageArray) {
free(value);
}
The problem is that the app then crashes during this process. All I get is the EXC_BAD_ACCESSS error message and a pointer to the following line of code in the loadModel method above :
[pool release];
Nothing in the stack trace. I have also tried turning on NSZombie, NSAutoreleaseTrackFreedObjectCheck and NSDebugEnabled, but I still don't get any additional information.
The odd thing is that if I put a delay on the button of 2 seconds (i.e only trigger the freeUpMallocedMemory method after 2 seconds), the app no longer crashes and works fine.
Can anyone suggest what might be causing this - really confused and have already spent a few days troubleshooting.
Thank you !
You are over-releasing... the values in pointerStorageArray are created via a convenience method and as such don't need releasing, simply removing them from the array will dispose of them.

How to control Network Activity Indicator on iPhone

I know that in order to show/hide the throbber on the status bar I can use
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
But my program sends comm requests from many threads, and I need a location to control whether the throbber should be shown or hidden.
I thought about a centralized class where every comm request will register and this class will know if one-or-many requests are currently transferring bytes, and will turn the throbber on, otherwise - off.
Is this the way to go? why haven't Apple made the throbber appear automatically when networking is happening
Try to use something like this:
static NSInteger __LoadingObjectsCount = 0;
#interface NSObject(LoadingObjects)
+ (void)startLoad;
+ (void)stopLoad;
+ (void)updateLoadCountWithDelta:(NSInteger)countDelta;
#end
#implementation NSObject(LoadingObjects)
+ (void)startLoad {
[self updateLoadCountWithDelta:1];
}
+ (void)stopLoad {
[self updateLoadCountWithDelta:-1];
}
+ (void)updateLoadCountWithDelta:(NSInteger)countDelta {
#synchronized(self) {
__LoadingObjectsCount += countDelta;
__LoadingObjectsCount = (__LoadingObjectsCount < 0) ? 0 : __LoadingObjectsCount ;
[UIApplication sharedApplication].networkActivityIndicatorVisible = __LoadingObjectsCount > 0;
}
}
UPDATE: Made it thread safe
Having some logic in your UIApplication subclass singleton seems like the natural way to handle this.
//#property bool networkThingerShouldBeThrobbingOrWhatever;
// other necessary properties, like timers
- (void)someNetworkActivityHappened {
// set a timer or something
}
- (void)networkHasBeenQuietForABit
// turn off the indicator.
// UIApplcation.sharedApplication.networkActivityIndicatorVisible = NO;
}