c_cpp Taptic API for iPhone 7,7 Plus(公共API)。还适用于iPhone 6s,6s Plus(私有API)。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Taptic API for iPhone 7,7 Plus(公共API)。还适用于iPhone 6s,6s Plus(私有API)。相关的知识,希望对你有一定的参考价值。


// StackOverflow: Taptic in iOS 9
// http://stackoverflow.com/a/36320245/3283039

#import <Foundation/Foundation.h>
#import <UIKit/UIDevice.h>
@import AudioToolbox;
#include <sys/sysctl.h>

#define VER_10_0_OR_LATER       ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0f)


NS_INLINE NSString * ext_deviceType()
{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    return platform;
}

#define IPHONE_TAPTIC_OLD       ([ext_deviceType() isEqualToString:@"iPhone8,1"] || [ext_deviceType() isEqualToString:@"iPhone8,2"])

NS_INLINE void tapticNotificationWithStyle(UINotificationFeedbackType type) {
    if (!VER_10_0_OR_LATER) return;
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    UINotificationFeedbackGenerator *taptic = [[UINotificationFeedbackGenerator alloc] init];
    [taptic prepare];
    [taptic notificationOccurred:type];
}

NS_INLINE void tapticNotificationError() {
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    if (IPHONE_TAPTIC_OLD) {
        AudioServicesPlaySystemSound(1521);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        UINotificationFeedbackGenerator *taptic = [[UINotificationFeedbackGenerator alloc] init];
        [taptic prepare];
        [taptic notificationOccurred:UINotificationFeedbackTypeError];
    }
}

NS_INLINE void tapticNotificationWarning() {
    if (!VER_10_0_OR_LATER) return;
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    UINotificationFeedbackGenerator *taptic = [[UINotificationFeedbackGenerator alloc] init];
    [taptic prepare];
    [taptic notificationOccurred:UINotificationFeedbackTypeWarning];
}

NS_INLINE void tapticNotificationSuccess() {
    if (!VER_10_0_OR_LATER) return;
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    UINotificationFeedbackGenerator *taptic = [[UINotificationFeedbackGenerator alloc] init];
    [taptic prepare];
    [taptic notificationOccurred:UINotificationFeedbackTypeSuccess];
}

NS_INLINE void tapticImpactWithStyle(UIImpactFeedbackStyle style) {
    if (!VER_10_0_OR_LATER) return;
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    UIImpactFeedbackGenerator *taptic = [[UIImpactFeedbackGenerator alloc] initWithStyle:style];
    [taptic prepare];
    [taptic impactOccurred];
}

NS_INLINE void tapticImpactLight() {
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    if (IPHONE_TAPTIC_OLD) {
        //AudioServicesPlaySystemSound(1519);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        tapticImpactWithStyle(UIImpactFeedbackStyleLight);
    }
}

NS_INLINE void tapticImpactMedium() {
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    if (IPHONE_TAPTIC_OLD) {
        AudioServicesPlaySystemSound(1519);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        tapticImpactWithStyle(UIImpactFeedbackStyleMedium);
    }
}

NS_INLINE void tapticImpactHeavy() {
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    if (IPHONE_TAPTIC_OLD) {
        AudioServicesPlaySystemSound(1520);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        tapticImpactWithStyle(UIImpactFeedbackStyleHeavy);
    }
}

NS_INLINE void tapticSelection() {
    if (![OHJGlobal shared].tapticEngineEnabled) return;
    if (IPHONE_TAPTIC_OLD) {
        //AudioServicesPlaySystemSound(1519);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        UISelectionFeedbackGenerator *taptic = [[UISelectionFeedbackGenerator alloc] init];
        [taptic prepare];
        [taptic selectionChanged];
    }
}
        [taptic notificationOccurred:UINotificationFeedbackTypeError];
    }
}

NS_INLINE void tapticNotificationWarning() {
    if (!VER_10_0_OR_LATER) return;
    UINotificationFeedbackGenerator *taptic = [[UINotificationFeedbackGenerator alloc] init];
    [taptic prepare];
    [taptic notificationOccurred:UINotificationFeedbackTypeWarning];
}

NS_INLINE void tapticNotificationSuccess() {
    if (!VER_10_0_OR_LATER) return;
    UINotificationFeedbackGenerator *taptic = [[UINotificationFeedbackGenerator alloc] init];
    [taptic prepare];
    [taptic notificationOccurred:UINotificationFeedbackTypeSuccess];
}

NS_INLINE void tapticImpactWithStyle(UIImpactFeedbackStyle style) {
    if (!VER_10_0_OR_LATER) return;
    UIImpactFeedbackGenerator *taptic = [[UIImpactFeedbackGenerator alloc] initWithStyle:style];
    [taptic prepare];
    [taptic impactOccurred];
}

NS_INLINE void tapticImpactLight() {
    if (IPHONE_TAPTIC_OLD) {
        //AudioServicesPlaySystemSound(1519);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        tapticImpactWithStyle(UIImpactFeedbackStyleLight);
    }
}

NS_INLINE void tapticImpactMedium() {
    if (IPHONE_TAPTIC_OLD) {
        AudioServicesPlaySystemSound(1519);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        tapticImpactWithStyle(UIImpactFeedbackStyleMedium);
    }
}

NS_INLINE void tapticImpactHeavy() {
    if (IPHONE_TAPTIC_OLD) {
        AudioServicesPlaySystemSound(1520);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        tapticImpactWithStyle(UIImpactFeedbackStyleHeavy);
    }
}

NS_INLINE void tapticSelection() {
    if (IPHONE_TAPTIC_OLD) {
        //AudioServicesPlaySystemSound(1519);
    }
    else {
        if (!VER_10_0_OR_LATER) return;
        UISelectionFeedbackGenerator *taptic = [[UISelectionFeedbackGenerator alloc] init];
        [taptic prepare];
        [taptic selectionChanged];
    }
}


以上是关于c_cpp Taptic API for iPhone 7,7 Plus(公共API)。还适用于iPhone 6s,6s Plus(私有API)。的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp Hello World for C ++

c_cpp #For循环Swift3.c

c_cpp for raspberry pi 2视频模块输入

c_cpp 基本的windows api

c_cpp 海思运行时API学习记录

c_cpp AMS_API.cpp