Objective C方法在Objective C ++中无法正常工作

时间:2013-05-03 06:05:40

标签: ios objective-c xcode objective-c++

我在目标C ++类中调用了一个客观的C方法,我创建了一个标签,同时隐藏了状态栏,但状态栏隐藏得很好,而标签没有被创建和显示!如果我在除了这个目标C ++类以外的任何地方调用该方法,它可以正常工作而没有任何问题

Objective C ++类位于

之下
void audioRouteChangeListenerCallback (void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue )

{
   // ensure that this callback was invoked for a route change
   if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;

   {
       // Determines the reason for the route change, to ensure that it is not
       //      because of a category change.
       CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;

       CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason) );
       SInt32 routeChangeReason;
       CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);

       if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
            //Handle Headset Unplugged
           NSLog(@"PluggedOut");


       }
       else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable)
       {
           //Handle Headset plugged in
           NSLog(@"Something Plugged In");

           audiotest *test = [[audiotest alloc] init];
           ArmorController *armorcontroller =[[ArmorController alloc]init];


       NSLog(@"%d", [test Checkheadphonestatus]);
            if([test Checkheadphonestatus] == 1)
            {
         [armorcontroller deviceconnectedalert];
            }
            else if([test Checkheadphonestatus] == 0)
            {
                NSLog(@"Device not connected");
            }


       }


   }

在目标C ++类中没有正确执行的目标C方法在

之下
- (void) deviceconnectedalert
{

   [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];


     self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 320, 30)];
    [self.titleLabel setText:@"Device Connected Successfully!"];
    self.titleLabel.backgroundColor =[UIColor redColor];
    [self.view addSubview:self.titleLabel];

}

0 个答案:

没有答案