因此,我主要用swift编写,但似乎只有在Objective-c中调用此'AudioServicesPlaySystemSoundWithVibration'的方法...开始时,代码我写了没有工作,我不知道什么改变了,但它给了我现在的错误“隐式函数声明'AudioServicesPlaySystemSoundWithVibration'在C99中无效”,而不是仅仅是一个警告。同样的警告和错误标题,但现在它是我无法编译的错误。是的,我知道我正在使用私人API,但我不打算出售该应用程序,所以我不在乎苹果是怎么想的。我只需要有自定义振动。这两个函数vibrateMutate和vibrateSection在独立的swift文件中都被调用,并且在创建我的objective-c文件时,我将'import vibrate.h'放置在Bridging Header中,这是我创建的。这里是我的代码:)函数'AudioServicesPlaySystemSoundWithVibration'的隐式声明在C99错误中无效
//vibrate.h FILE NAME
#ifndef vibrate_h
#define vibrate_h
@interface Vibrate : NSObject
+ (void)vibrateMutate;
+ (void)vibrateSectionChange;
@end
#endif /* vibrate_h */
// vibrate.m FILE NAME
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioServices.h>
#import <AudioToolbox/AudioToolbox.h>
#import "vibrate.h"
@implementation Vibrate
+ (void) vibrateMutate
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array ];
[arr addObject:[NSNumber numberWithBool:YES]];
[arr addObject:[NSNumber numberWithInt:50]];
[arr addObject:[NSNumber numberWithBool:NO]];
[arr addObject:[NSNumber numberWithInt:10]];
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithDouble:.25] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict); //ERROR
}
+ (void) vibrateSectionChange
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
NSMutableArray* arr = [NSMutableArray array ];
[arr addObject:[NSNumber numberWithBool:YES]];
[arr addObject:[NSNumber numberWithInt:150]];
[arr addObject:[NSNumber numberWithBool:NO]];
[arr addObject:[NSNumber numberWithInt:10]];
[dict setObject:arr forKey:@"VibePattern"];
[dict setObject:[NSNumber numberWithDouble:.75] forKey:@"Intensity"];
AudioServicesPlaySystemSoundWithVibration(4095,nil,dict);
}
@end
感谢您的意见,是的,我们知道我们无法提交到App Store,但这是一个个人项目,所以我们并不太担心。 :) –
不用担心,我知道你在你的问题中提到过,但总是有分心的人不知道其含义,也许这可以节省一些时间给他们;-) – GoRoS