2

I am building a tweak for SMS sending on the default MobileSMS app coming with iOS 6.1. Even though I have managed to hook to the "Send" button, I cannot create a popup to inform the user, neither with UIAlertView nor with a UIViewController. I think the problem is that the CTMmsEncoder class I am hooking to does not have a view controller to somehow override.

My question is if there is some way I can make a view appear in a situation like this. I have gone through many source codes for tweaks, but cannot find a similar case. I have even tried to create a dylib and load a a UIViewController from there, but get the (expected) error:

Oct 25 14:37:59 Pudge SpringBoard[950] <Warning>: Warning: Attempt to present <ModalViewController: 0x1dbbe1a0> on <KSMSDylibViewOne: 0x1db7da50> whose view is not in the window hierarchy!

When trying to implement a class with a ViewController directly in my tweak (say class ModalViewController), then Theos obviously outputs the error:

Tweak.xm:12:6: error: instance method 'presentViewController:animated:completion:' is being used on 'Class' which is not in the root class
      [-Werror,-Wobjc-method-access]
    [self presentViewController:view animated:YES completion:nil];
    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Is there any way to get past this, or do I have to redesign?

Thank you in advance,

Panagiotis.

Panagiotis
  • 309
  • 2
  • 13

1 Answers1

2

If you're simply looking to create something like what you get with UIAlertView, you should be able to use CFUserNotificationCreate(), even in a situation where you don't have a proper view hierarchy.

See this answer by KennyTM, or another one I posted here ... skipping to the Notify User from Daemon section, item (2).

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • That is obviously a very good approach, but would it be able to allow user input? If I wanted to add a password for the user to type in before sending an SMS, your proposal (2) would only create an alert, or (1) open up another application (if I got it correctly), right? – Panagiotis Oct 26 '13 at 09:19
  • @Panagiotis, if by "user input", you mean adding a text field or something like that ... no, it won't. But, `UIAlertView`, mentioned in your question, doesn't either. That's right, my proposal (2) in the linked answer is just a popup alert, while (1) is a way to completely open up a UI application (from a background daemon in that case). Hope that makes things more clear. – Nate Oct 26 '13 at 09:32
  • 1
    @Panagiotis, actually, I may have to correct myself. The exact code I show does not give you anything but buttons, but if you look [at the Apple docs here](https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFUserNotificationRef/Reference/reference.html), it seems that you can also create text fields in your alert. This is a Mac OS X set of APIs, so if you have a follow up question on how to customize the CFUserNotification, you might tag it `osx` instead of `iphone` or `ios`. The same APIs should work on iOS, they're just *private*. – Nate Oct 26 '13 at 09:34
  • yes you are right! I guess a text field can be added - I will worry later about how to implement it. I cannot seem to be able to `make` your code though - I get `error: '__bridge' casts have no effect when not using ARC [-Werror,-Warc-bridge-casts-disallowed-in-nonarc] [dict setObject: @"Alert!" forKey: (__bridge NSString*)kCFUserNotificationAlertHeaderKey];` so I somehow have to tell theos to use ARC (?). – Panagiotis Oct 26 '13 at 09:42
  • @Panagiotis, yes the code I posted was written for ARC. You can either figure out how to enable ARC in your theos build settings, or just change my code to do it the old, non-ARC way. I think you'd just change `(__bridge NSString*)` to a straight cast: `(NSString*)`. – Nate Oct 26 '13 at 09:52
  • Epic! Finally alert pops!! Now have to figure out how to stop the iOS from sending the message before the user enters his password (actually make it modal)! Thank you so much (again) Nate! – Panagiotis Oct 26 '13 at 10:00