title: Blocking incoming sms in iOS 7
body: <p>I want to write a tweak for jailbroken devices that blocks messages from a phone number(in iOS 7). First I used the second answer of creker in <a href="https://stackoverflow.com/questions/16219799/block-sms-on-ios6">this link</a> for writing the tweak. Here is my code:</p>
  
  <pre><code>#import &lt;substrate.h&gt;
  #import &lt;UIKit/UIKit.h&gt;
  #import &lt;Foundation/Foundation.h&gt;
  #import &lt;libkern/OSAtomic.h&gt;
  #import "CTMessage.h"
  #import "CTMessageCenter.h"
  
  id(*_processReceivedMessage_orig)(id, SEL, CTMessage*) = NULL;
  id _processReceivedMessage_hooked(id self, SEL _cmd, CTMessage* msg);
  %hook IMDService
  -(void)loadServiceBundle:(NSBundle*)bundle
  {    
      if ([[bundle bundleIdentifier] isEqualToString:@"com.apple.SMSPlugin"] &amp;&amp; [bundle isLoaded]) // not sure if the bundle identifier is correct!
      {  
          MSHookMessageEx(objc_getClass("SMSServiceSession"),
                          @selector(_processReceivedMessage:),
                          (IMP)_processReceivedMessage_hooked,
                          (IMP*)&amp;_processReceivedMessage_orig);
      }
  }
  %end
  
  id _processReceivedMessage_hooked(id self, SEL _cmd, CTMessage* msg)
  {
      NSObject&lt;CTMessageAddress&gt;* phonenumber = [msg sender];
      NSString *senderNumber = (NSString*) [phonenumber canonicalFormat]; // sender number
  
      if ([senderNumber isEqualToString:@"+012345678910"])
          [[CTMessageCenter sharedMessageCenter] acknowledgeIncomingMessageWithId:[msg messageId]];
      else
           return _processReceivedMessage_orig(self, _cmd, msg);
  }
  </code></pre>
  
  <p>and my plist file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
      &lt;key&gt;Filter&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;Bundles&lt;/key&gt;
          &lt;array&gt;
              &lt;string&gt;com.apple.imagent&lt;/string&gt;
          &lt;/array&gt;
      &lt;/dict&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>The main problem is that <code>loadServiceBundle</code> never gets hooked and my function never gets called! If I install the tweak on the iPhone, nothing happens when mobile has incoming sms and message alert comes. I myself think that the problem is I’m writing for iOS 7 but the question is for iOS 6. If the problem is this, could you tell what should I have to do?</p>
  
  <p>Another question that I have is in the <code>loadServiceBundle</code> method. As you can see in the written code, I don’t exactly know which bundle identifier should I filter. Please tell me if I’ve chosen the right bundle identifier.</p>
  
  <p>I would be glad to tell me if I have any other problems in my code.</p>