simple theos tweak fails - ios

I am new to development with Theos, so i decided to try a simple tweak from a tutorial. The tweak compiles and installs correctly, but it does not work when I test it on my iPad mini with iOS 8.4, using the iOS 8.1 SDK. This is a copy of the code from the tutorial I used:
%hook SBApplicationIcon
-(void)launch
{
NSString *appName = [self displayName];
NSString *message = [NSString stringWithFormat:#"The app %# has been launched", appName, nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:appName message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end

Related

iOS7 UIAlertView EXC_BAD_ACCESS when set UIAlertViewStylePlainTextInput

I'm trying to show UIAlertView for iOS 7 device with input field so i have method
- (void)createAlertView
{
NSString *msg = #"Description (optional)";
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:lastMarkAsOutdatedActionTitle
message:msg
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Confirm", nil];
myAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
[myAlert show];
}
which I'm calling like this
[self performSelectorOnMainThread:#selector(createAlertView) withObject:nil waitUntilDone:NO];
but at the line myAlert.alertViewStyle = UIAlertViewStylePlainTextInput; I'm getting error Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)
I created clean project and tested this code - it works so I stucked with it. Any ideas?
Update
Screens at the moment of error

How to resize UIAlertView in iOS 7

Currently I'm using this code but it doesn't work in iOS 7. It works fine in iOS 6:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:Nil, nil];
[alertView show];
- (void)willPresentAlertView:(UIAlertView *)alertView {
[alertView setFrame:CGRectMake(alertView.frame.origin.x, alertView.frame.origin.y, alertView.frame.size.width, 200)];
}
How can we resize in iOS 7?

Get Device Type/ Model

After looking on SO in to how to detect users device here: iOS - How to get device make and model?
I made a quick test app to display an alert depending on device. I get no alert from this code. What am I missing/doing wrong here?
#import "ViewController.h"
#import <sys/utsname.h>
NSString* machineName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
#interface ViewController ()
#end
- (IBAction)btn:(id)sender {
if ([machineName() isEqualToString:#"iPhone5,1"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Checking device iphone5" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
} else if ([machineName() isEqualToString:#"iPhone4,1"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Checking device iphone4" delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
}
}
The machine field of struct utsname is the machine hardware platform and that is "x86_64" if the program is running in the iOS Simulator.
Only on a real device you will get strings like "iPhone5,1".

How can I share the contents of my page in iPhone app on facebook?

I'm providing a facebook share option on my iPhone app screen and need to share some images and URL on the user's facebook profile . I know there are several third party frameworks like ShareKit and other features like facebook sdk for iOS, but which is the best way I could so the same and i need to get the share button with the number of shares until now as shown in the image below
and on clicking should redirect to authentication.
And should be compatible with iOS5 and above, hope my question is clear.
Thanks in advance
Solved the question myself through research
I used Facebook Graph API since my application needs support from iOS4+, would have been simple if it was for iOS6 as iOS6 has Facebook integration and needs just a few lines of code to implement it.
Imported Graph APi files and added the following code:
#synthesize facebook;
//login with facebook
- (IBAction) facebookButtonPressed {
if (!facebook || ![facebook isSessionValid]) {
self.facebook = [[[Facebook alloc] init] autorelease];
NSArray *perms = [NSArray arrayWithObjects: #"read_stream", #"create_note", nil];
[facebook authorize:FACEBOOK_API_KEY permissions:perms delegate:self];
}
else {
[self fbDidLogin];
}
}
//upload image once you're logged in
-(void) fbDidLogin {
[self fbUploadImage];
}
- (void) fbUploadImage
{
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
resultImage, #"picture",
nil];
[facebook requestWithMethodName: #"photos.upload"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
self.currentAlertView = [[[UIAlertView alloc]
initWithTitle:NSLocalizedString(#"Facebook", #"")
message:NSLocalizedString(#"Uploading to Facebook.", #"")
delegate:self
cancelButtonTitle:nil
otherButtonTitles: nil] autorelease];
[self.currentAlertView show];
}
//facebook error
- (void)request:(FBRequest*)request didFailWithError:(NSError*)error
{
[self.currentAlertView dismissWithClickedButtonIndex:0 animated:YES];
self.currentAlertView = nil;
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(#"Error", #"")
message:NSLocalizedString(#"Facebook error message", #"")
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
[myAlert show];
[myAlert release];
}
//facebook success
- (void)request:(FBRequest*)request didLoad:(id)result
{
[self.currentAlertView dismissWithClickedButtonIndex:0 animated:YES];
self.currentAlertView = nil;
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(#"Facebook", #"")
message:NSLocalizedString(#"Uploaded to Facebook message", #"")
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
[myAlert show];
[myAlert release];
}
And to get the share count of a particular URL in facebook,
use
http://graph.facebook.com/?id=url
But this returns the count of all likes,shares and posts altogether, so better find some alternatives to do so.
Hope this helps
Thanks

Writetourl does not work

I have tried for a week to get writeToUrl to work, but no... nothing.
I simply want to update a file on my server from an iPhone app.
This is the code:
NSURL *url = [NSURL URLWithString:#"http://user:pw#192.168.120.167/test.txt"];
NSString *teststring = #"it works";
if ([teststring writeToURL:url atomically:YES encoding:NSASCIIStringEncoding error:nil]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Status" message: #"Yessss" delegate: self cancelButtonTitle: #"Close" otherButtonTitles: nil];
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Status" message: #"Noooooo" delegate: self cancelButtonTitle: #"Close" otherButtonTitles: nil];
[alert show];
[alert release];
}
I switched from writeToURL to writeToFile, using the exact same file path, and it suddenly worked. Seems like there might be a bug in writeToURL. This was tested on iOS 7.1.
You can only write to local files. See documentation:
Since at present only file:// URLs are supported, there is no difference between this method and writeToFile:options:error:, except for the type of the first argument.

Resources