Ios 目标C++内部不正确的C++方法
我在C++中调用了一个目标C方法,在这里我创建了一个标签,它隐藏了状态栏,但是状态栏隐藏得很好,而标签没有被创建和显示!如果我将该方法称为除此目标C++类之外的其他任何对象,则它工作良好而没有任何问题 <目标C++类低于Ios 目标C++内部不正确的C++方法,ios,objective-c,xcode,objective-c++,Ios,Objective C,Xcode,Objective C++,我在C++中调用了一个目标C方法,在这里我创建了一个标签,它隐藏了状态栏,但是状态栏隐藏得很好,而标签没有被创建和显示!如果我将该方法称为除此目标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];
}
您的文件扩展名是.mm,对吗?只需确保deviceconnectedalert在主线程上运行。是@有其.mmonly@Hamdullahshah如何做到这一点?调度\u异步调度\u获取\u主队列,^{///在这里工作};