Code for Two Essential Buttons: Write a Review and Send a Letter To Developers. These buttons are often required in a mobile application to collect a feedback from users and to allow them write a review to your app more quickly and comfortable. It also includes some system information. It is in Russian, but no problem to translate it.
- (void)writeReviewClicked
{
NSString *url = @"https://itunes.apple.com/ru/app/yourapp.ru/id662863746?mt=8";
NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escapedUrl]];
}
- (void)sendLetterClicked
{
NSString *subject = [NSString stringWithFormat:@"%@ %@", @"Письмо от пользователя мобильного приложения", @"YourApp для iOS"];
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeStyle = NSDateFormatterMediumStyle;
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
NSString *todayString = [dateFormatter stringFromDate:today];
NSMutableString *temp = [NSMutableString new];
[temp appendFormat:@"\n\n\n\n\n-----------------------\nCистемная информация может помочь нам в отладке приложения.\n-----------------------\n"];
[temp appendFormat:@"Версия приложения: %@\n", UD_OBJECT(UDKeyVersion)];
[temp appendFormat:@"Версия iOS: %@\n", [[UIDevice currentDevice] systemVersion]];
[temp appendFormat:@"Устройство: %@\n", [[UIDevice currentDevice] deviceName]];
[temp appendFormat:@"Интернет соединение: %@\n", [[RRHelper defaultHelper] networkStatusString]];
[temp appendFormat:@"Имя пользователя: %@ \n", UD_OBJECT(UDKeyPersonEmail)];
[temp appendFormat:@"Дата: %@ \n", todayString];
[temp appendFormat:@"-----------------------\n"];
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
[controller setSubject:subject];
[controller setToRecipients:@[@"your@email.ru"]];
[controller setMessageBody:temp isHTML:NO];
controller.mailComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
#pragma mark - MFMailComposeViewControllerDelegate
- (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result) {
case MFMailComposeResultCancelled:
{
break;
}
case MFMailComposeResultFailed:
{
[RRHelper showErrorMessage:@"Не удалось отправить письмо."];
break;
}
case MFMailComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
Use this category to get a more precise device name:
//
// UIDevice+machine.m
//
// Created by Dennis Kutlubaev on 15.11.13.
//
#import "UIDevice+machine.h"
#import
@implementation UIDevice(deviceName)
- (NSString*)deviceName {
struct utsname systemInfo;
uname(&systemInfo);
NSString *machineName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSDictionary *commonNamesDictionary =
@{
@"i386": @"iPhone Simulator",
@"x86_64": @"iPad Simulator",
@"iPhone1,1": @"iPhone",
@"iPhone1,2": @"iPhone 3G",
@"iPhone2,1": @"iPhone 3GS",
@"iPhone3,1": @"iPhone 4",
@"iPhone3,2": @"iPhone 4(Rev A)",
@"iPhone3,3": @"iPhone 4(CDMA)",
@"iPhone4,1": @"iPhone 4S",
@"iPhone5,1": @"iPhone 5(GSM)",
@"iPhone5,2": @"iPhone 5(GSM+CDMA)",
@"iPhone5,3": @"iPhone 5c(GSM)",
@"iPhone5,4": @"iPhone 5c(GSM+CDMA)",
@"iPhone6,1": @"iPhone 5s(GSM)",
@"iPhone6,2": @"iPhone 5s(GSM+CDMA)",
@"iPad1,1": @"iPad",
@"iPad2,1": @"iPad 2(WiFi)",
@"iPad2,2": @"iPad 2(GSM)",
@"iPad2,3": @"iPad 2(CDMA)",
@"iPad2,4": @"iPad 2(WiFi Rev A)",
@"iPad2,5": @"iPad Mini(WiFi)",
@"iPad2,6": @"iPad Mini(GSM)",
@"iPad2,7": @"iPad Mini(GSM+CDMA)",
@"iPad3,1": @"iPad 3(WiFi)",
@"iPad3,2": @"iPad 3(GSM+CDMA)",
@"iPad3,3": @"iPad 3(GSM)",
@"iPad3,4": @"iPad 4(WiFi)",
@"iPad3,5": @"iPad 4(GSM)",
@"iPad3,6": @"iPad 4(GSM+CDMA)",
@"iPod1,1": @"iPod 1st Gen",
@"iPod2,1": @"iPod 2nd Gen",
@"iPod3,1": @"iPod 3rd Gen",
@"iPod4,1": @"iPod 4th Gen",
@"iPod5,1": @"iPod 5th Gen",
};
NSString *deviceName = commonNamesDictionary[machineName];
if (deviceName == nil) {
deviceName = machineName;
}
return deviceName;
}
@end
And use this method in your helper class to create a user friendly network status string using Reachability class instance:
- (NSString *)networkStatusString
{
NetworkStatus networkStatus = [AppDel.reachability currentReachabilityStatus];
/*NotReachable = 0,
ReachableViaWiFi = 2,
ReachableViaWWAN = 1*/
switch (networkStatus) {
case NotReachable:
_networkStatusString = @"Нет соединения.";
break;
case ReachableViaWiFi: {
_networkStatusString = @"Wi-Fi";
break;
}
case ReachableViaWWAN: {
_networkStatusString = @"WWAN";
break;
}
default:
break;
}
return _networkStatusString;
}
References:
http://stackoverflow.com/questions/8292246/how-to-programmatically-differentiate-between-iphone-4-and-iphone-4s
http://iosdevelopertips.com/device/determine-if-iphone-is-3g-or-3gs-determine-if-ipod-is-first-or-second-generation.html