你是否曾经测试过应用?如果你测试过,你会知道用户报告他们找到的虫子是最重要的。BugButton 使 beta 测试者报告虫子变得几乎毫不费力。除了 UIKit 之外,没有其他依赖项,所以你只需要将 BugButton 类和资源拖入您的项目即可!
有两种方法
1. 下载源代码并将其拖入项目
2. 将 pod 'BugButton'
添加到 Podfile 并运行 pod install
注意:如果您尚未在项目中集成 CocoaPods,您可以在 cocoapods.org 了解如何添加
- (void)reportBug:(BugButton *)sender
代理方法。这是用户按下 bug 按钮时要自定义发生的操作的地点。在这个示例(来自所包含的示例项目)中,按下 bug 按钮将弹出一个用户可以填写的电子邮件表单。它还附加了当前应用状态的截图,以及设备型号、操作系统版本和应用版本以供诊断。
AppDelegate.h
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#import "BugButton.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate, BugButtonDelegate, MFMailComposeViewControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate {
BugButton *bugButton;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
ViewController *viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
bugButton = [BugButton bugButton];
bugButton.delegate = self;
[self.window addSubview:bugButton];
return YES;
}
- (void)reportBug:(BugButton *)sender
{
NSLog(@"BUG REPORT");
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *cannotEmailAlert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"This device is not set up to send email."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[cannotEmailAlert show];
return;
}
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
[mailViewController setMailComposeDelegate:self];
[mailViewController setToRecipients:@[@"[email protected]"]];
[mailViewController setSubject:@"Bug Report"];
[mailViewController setMessageBody:[sender bugReportString] isHTML:NO];
[mailViewController addAttachmentData:[sender getScreenshot] mimeType:@"image/jpeg" fileName:@"screenshot"];
[self.window.rootViewController presentViewController:mailViewController animated:YES completion:nil];
[sender removeFromSuperview];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
[self.window addSubview:bugButton];
}
@end
请随时通过电子邮件 [email protected]与我联系,提出任何问题或(讽刺的)你发现的任何虫子。