Cricket 是一个 iOS 库,用于从您的应用内发送反馈。
#import <NPCricket/NPCricket.h>
#import <NPCricket/NPNativeEmailHandler.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NPNativeEmailHandler *nativeEmailHandler = [NPNativeEmailHandler handlerWithToEmailAddress:@"[email protected]"];
[NPCricket useHandler:nativeEmailHandler];
// ... your code here ...
return YES;
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
[NPCricket show];
}
}
Cricket 不会自动显示。相反,您必须自己调用 [NPCricket show]
。上面的示例使用摇动手势触发 Cricket。它还通过电子邮件发送反馈。您可以根据自己的喜好定制和配置这两者。
Cricket 使用 "处理器" 来处理反馈。任何类都可以通过遵守 NPCricketHandler
协议成为处理器。自定义处理器的示例可以是直接将反馈发送到您的服务器的东西。
为了您的方便,我已经包括了一个用于使用内置电子邮件创建器(NPNativeEmailHandler
)的处理器。
如果您想创建自己的处理器,只需创建一个遵守 NPCricketHandler
的类并实现单一种方法,如下所示
#import "NPCricketHandlerProtocol.h"
@interface MyCustomHandler : NSObject <NPCricketHandler>
@end
@implementation MyCustomHandler
- (void)NPCricket_handleFeedback:(NPFeedback *)feedback {
// Do something with the feedback ...
}
@end
别忘了告诉 NPCricket
使用您的处理器。
MyCustomHandler *myCustomHandler = [[MyCustomHandler alloc] init];
[NPCricket useHandler:myCustomHandler];
Cricket 需要 iOS 8.0 和更高版本。
NPCricket 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile:
pod "NPCricket"
Nebojsa Petrovic, [email protected]
NPCricket 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。