0

I used the iOSOpenDev to create a Logos Tweak to hook the acknowledgeIncomingMessageWithId: of CTMessageCenter and I want to send notification by NSNotificationCenter to another app, but it doesn't work. I think that the NSNotificationCenter can work between different apps. I tried to test the NSNotificationCenter in tweak, first. That's what I did below:

%hook CTMessageCenter

-(void)acknowledgeIncomingMessageWithId:(unsigned int)anId {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(doingSMS) 
                                                     name:@"SMSComing" 
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"SMSComing" object:nil];
    }

    %orig;
}

- (void)doingSMS{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"短信消息传送成功" 
                                                    message:@"来短信啦"
                                                   delegate:nil 
                                          cancelButtonTitle:@"Good" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
}

%end

But it doesn't work. Also,the UIAlertView is not appearing. Who can tell me why?

Nate
  • 31,017
  • 13
  • 83
  • 207
Piosa
  • 1
  • 1

2 Answers2

1

To make notifications work between apps:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), 
                                NULL, 
                                doingSMS,
                                CFSTR("com.your.company.SMSComing"), 
                                NULL, 
                                CFNotificationSuspensionBehaviorCoalesce);

and then

CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), 
                                     CFSTR("com.your.company.SMSComing"), 
                                     NULL, 
                                     NULL, 
                                     TRUE);

Note that notification name like "SMSComing" (without a prefix) is liable to problems.

Nate
  • 31,017
  • 13
  • 83
  • 207
0

I had issues with UIAlertViews not appearing in a tweak I was working on with iOSOpenDev.
I realized I had to set the delegate of the UIAlertView to self. For some reason that I don't understand, when I had the delegate set as nil the UIAlertView wouldn't appear.

Ponyboy47
  • 924
  • 9
  • 15