Starting app on text message receive using theos tweak - ios

I'm trying to start an app if I receive an text message from an special sender.
Currently my Tweak.xm looks like this:
#import <SpringBoard/SpringBoard.h>
#import <UIKit/UIKit.h>
#import <ChatKit/ChatKit.h>
#import <ChatKit/CKSMSMessage.h>
#import <ChatKit/CKSMSEntity.h>
#import <ChatKit/CKSMSService.h>
#import <ChatKit/CKConversation.h>
#import <CoreTelephony/CoreTelephony.h>
%hook SMSCTServer
- (void)_ingestIncomingCTMessage:(CTMessage *)arg1
{
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Received :D!"
delegate:nil
cancelButtonTitle:#";)"
otherButtonTitles:nil];
[alert show];
[alert release];
}
%end
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application {
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Test!"
delegate:nil
cancelButtonTitle:#"Test"
otherButtonTitles:nil];
[alert show];
[alert release];
}
%end
%hook CKSMSService
-(void)_receivedMessage:(CKSMSRecordRef)message replace:(BOOL)replace{
NSLog(#"received message %#", message);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome"
message:#"Welcome to your iPhone Brandon!"
delegate:nil
cancelButtonTitle:#"Thanks"
otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end
and this is the makefile:
include theos/makefiles/common.mk
TWEAK_NAME = Mytweak
Mytweak_FILES = Tweak.xm
Mytweak_FRAMEWORKS = ChatKit Foundation CoreGraphics UIKit AudioToolbox
Mytweak_PRIVATE_FRAMEWORKS = CoreTelephony
include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
install.exec "killall -9 SpringBoard"
But I donĀ“t know how to install the Coretelephonyframework, I always get the error:
Tweak.xm:8:9: fatal error: 'CoreTelephony/CoreTelephony.h' file not found
import <CoreTelephony/CoreTelephony.h>
Does anyone know how to install the framework into theos? I am completely new to jailbreakapp coding.

This answer shows how to use class dump to get the private headers for CoreTelephony. Once you have the headers put them in the include directory for theos. I think /var/theos/include is the default. I hope this helps.

CoreTelephony.h is unnecessary for your tweak

Related

simple theos tweak fails

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

Reduce alert view coding

All.
In my iOS app.
On many pages I am having Too many alerts and also with many Network conditions.
With too many alert texts I am fed up.
And Every time I have to put the same code.
Can I declare this Code in Some Helper Class ?
Or Reuse this Code ?
-(BOOL)checkInternetAndlocationServices {
if(IS_INTERNET) {
if([CLLocationManager locationServicesEnabled] &&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied){
return YES;
}
else
{
NSLog(#"Location services are disabled.");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Location services are off." message:#"This app requires an Location services." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Location Services", nil];
[alert setTag:NO_LOCATIONSERVICES];
[alert show];
return NO;
}
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Internet connection is off." message:#"This app requires an internet connection and locations services, please enable internet connection and location services." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Settings", nil];
[alert setTag:NO_INTERNET];
[alert show];
return NO;
}
}
Thanks.
Please edit this question, if you found it useful..
Thanks for giving good approaches, still any other ways, examples are most welcome.
You could make a helper class and use class methods to show alert.
You could also make a UIAlertView category and make a class method for showing alert.(Edit)
#implementation UIAlertView (MyAlert)
+(void) showAlertWithTitle:(NSString *)title message:(NSString *)message {
[[[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
#end
You could define a macro in .pch file or some helper header file for showing alert.#define Alert(title,msg,target) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:target cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show]
Alert(#"This is Title",#"This is message",self);
You can make an NSObject class and write method whether Instance or Class method like this and pass only the message and the delegate whether needs to set nil or self like this:-
+(void)showAlertViewWithAlertMessage:(NSString*)alertMessage withDelegate:(id)delegate
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Title" message:alertMessage delegate:delegate cancelButtonTitle:OK_TAP otherButtonTitles: nil];
[alert show];
}
You can use it like this:-
[Classname showAlertViewWithAlertMessage:#"your message" withDelegate:nil];

UIAlertView showing up on Simulator, but not device

I have UIAlertView working as expected in simulator, and earlier in my App's development it worked well on the device, but as of now it doesn't show up. I am however certain the code is running. Help would be greatly appreciated.
MacroEditViewController.h:
#interface MacroEditViewController : UIViewController <UIAlertViewDelegate>
MacoEditViewController.m:
- (IBAction)saveDatabase:(UIButton *)sender
{
[self alertStatusWithTitle:[NSString stringWithFormat:#"Are you sure you want to override %# for %#? This cannot be undone (But you can Reset All Overrides on Macros screen).", macroMeal[1], macroMeal[0]] :#"Update Macros"];
}
- (void) alertStatus:(NSString *)msg :(NSString *)title
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:#"Cancel", nil];
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
[self saveUpdatesToDatabase];
}
}
Why did you call your function like this
[self alertStatus:[#"Are you sure you want to override?"] :#"Update Macros"];
Call it like this
[self alertStatus:#"Are you sure you want to override?" :#"Update Macros"];
without the square brackets, it may be the problem
create a CIAlert.h
void CIAlert(NSString* title, NSString* alert);
void CIError(NSString* error);
and in CIAlert.m
#import "CIAlert.h"
void CIAlert(NSString* title, NSString* alert) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:alert delegate:nil
cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
void CIError(NSString* error) {
CIAlert(#"Error", error);
}
import the class CIAlert.h and call it just like this...
CIAlert(#"Title", #"Enter your message");

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".

UIAlertView crash in iOS 6

I have this code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
The problem is this code crash before it shows the alert, I have tested it on lower iOS and it work but on iOS 6 it crash.
I found the answer. I coded:
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];
instead of
[alert show];
it crash because the process might not be performed in the main thread.
Source from:
https://stackoverflow.com/a/12475858/1179680

Resources