Utilities.m
4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// Utilities.m
// LifeLog
//
// Created by Nguyen Van Phong on 7/29/17.
// Copyright © 2017 PhongNV. All rights reserved.
//
#import <Social/Social.h>
#import <LineKit/Line.h>
#import "Utilities.h"
@implementation Utilities
+ (NSString *)addCommaFromNumber:(NSInteger)number
{
NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
[fmt setNumberStyle:NSNumberFormatterDecimalStyle];
[fmt setMaximumFractionDigits:0];
NSString *result = [fmt stringFromNumber:@(number)];
return result;
}
+ (UIColor *)convertHecToColor:(int) hex
{
return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 \
green:((float)((hex & 0xFF00) >> 8))/255.0 \
blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
}
+ (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc
{
if (message.length > 0) {
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Error"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[vc presentViewController:alert animated:YES completion:nil];
}
}
+ (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[composeViewController setInitialText:content];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(@"canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(@"done");
break;
default:
break;
}
}];
[vc presentViewController:composeViewController animated:YES completion:nil];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=FACEBOOK"]];
}
}
+ (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeViewController setInitialText:content];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(@"canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(@"done");
break;
default:
break;
}
}];
[vc presentViewController:composeViewController animated:YES completion:nil];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=TWITTER"]];
}
}
+ (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc {
if (![Line isLineInstalled]) {
[self showErrorMessage:@"Install Line app first" withViewController:vc];
}
else {
[Line shareText:content];
}
}
+ (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc {
}
@end