iOS开发之诱导用户为自己的App评论功能

"由于我自己的App下载量少,评论也少,出于App的aso优化,想尽办法,而评论是aso里边比较重视的一块,前面的版本都没有诱导用户评论的这一功能,导致有些被动。"

由此自己简单的封装了该功能,下面我们先看看效果图:

blob.png

弹出试图并没有做什么处理,就是系统的8.0以前用的UIAlertView8.0以上用的UIAlertController

具体的一些算法,都可以看代码,闲话不多说,直接贴码

新建一个NSObject的类命名为LBToAppStore 具体代码如下

.h文件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

#import #import @interface LBToAppStore : NSObject{

    #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0

 

    UIAlertView *alertViewTest;

 

    #else

 

    UIAlertController *alertController;

 

    #endif

 

}

 

@property (nonatomic,strong) NSString * myAppID;//appID

 

 

 

- (void)showGotoAppStore:(UIViewController *)VC;

 

@end

.m文件

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

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

#import "LBToAppStore.h"

 

@implementation LBToAppStore

 

 

- (void)showGotoAppStore:(UIViewController *)VC{

    //当前版本号

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

    float appVersion = [[infoDictionary objectForKey:@"CFBundleShortVersionString"] floatValue];

    //userDefaults里的天数

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    int udtheDays = [[userDefaults objectForKey:@"theDays"] intValue];

    //userDefaults里的版本号

    float udAppVersion = [[userDefaults objectForKey:@"appVersion"] intValue];

    //userDefaults里用户上次的选项

    int udUserChoose = [[userDefaults objectForKey:@"userOptChoose"] intValue];

    //时间戳的天数

    NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];

    int daySeconds = 24 * 60 * 60;

    NSInteger theDays = interval / daySeconds;

 

    //版本升级之后的处理,全部规则清空,开始弹窗

    if (udAppVersion && appVersion>udAppVersion) {

        [userDefaults removeObjectForKey:@"theDays"];

        [userDefaults removeObjectForKey:@"appVersion"];

        [userDefaults removeObjectForKey:@"userOptChoose"];

        [self alertUserCommentView:VC];

    }

    //1,从来没弹出过的

    //2,用户选择????我要吐槽,7天之后再弹出

    //3,用户选择????残忍拒绝后,7天内,每过1天会弹一次

    //4,用户选择????残忍拒绝的30天后,才会弹出

    else if (!udUserChoose ||

    (udUserChoose==2 && theDays-udtheDays>7) ||

    (udUserChoose>=3 && theDays-udtheDaysudUserChoose-3) ||

    (udUserChoose>=3 && theDays-udtheDays>30))

    {

        [self alertUserCommentView:VC];

 

    }

 

}

 

-(void)alertUserCommentView:(UIViewController *)VC{

 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

 

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    //当前时间戳的天数

    NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];

    int daySeconds = 24 * 60 * 60;

    NSInteger theDays = interval / daySeconds;

    //当前版本号

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

    float appVersion = [[infoDictionary objectForKey:@"CFBundleShortVersionString"] floatValue];

    //userDefaults里版本号

    float udAppVersion = [[userDefaults objectForKey:@"appVersion"] intValue];

    //userDefaults里用户选择项目

    int udUserChoose = [[userDefaults objectForKey:@"userOptChoose"] intValue];

    //userDefaults里用户天数

    int udtheDays = [[userDefaults objectForKey:@"theDays"] intValue];

 

    //当前版本比userDefaults里版本号高

    if (appVersion>udAppVersion) {

        [userDefaults setObject:[NSString stringWithFormat:@"%f",appVersion] forKey:@"appVersion"];

    }

 

    alertController = [UIAlertController alertControllerWithTitle:@"致开发者的一封信" message:@"有了您的支持才能更好的为您服务,提供更加优质的,更加适合您的App,当然您也可以直接反馈问题给到我们" preferredStyle:(UIAlertControllerStyleAlert)];

 

    UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@"????残忍拒绝" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {

 

    [userDefaults setObject:@"1" forKey:@"userOptChoose"];

    [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];

    }];

 

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"????好评赞赏" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {

 

    [userDefaults setObject:@"2" forKey:@"userOptChoose"];

    [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];

 

    NSString *str = [NSString stringWithFormat:

    @"https://itunes.apple.com/cn/app/id%@?mt=8",

    self.myAppID ];

 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

 

    }];

 

    UIAlertAction *showAction = [UIAlertAction actionWithTitle:@"????我要吐槽" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {

 

    if (udUserChoose30) {

    [userDefaults setObject:@"3" forKey:@"userOptChoose"];

    [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];

    }else{

    [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)(theDays-udtheDays+3)] forKey:@"userOptChoose"];

    }

    NSString *str = [NSString stringWithFormat:

    @"https://itunes.apple.com/cn/app/id%@?mt=8",

    self.myAppID ];

 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

    }];

 

 

    [alertController addAction:refuseAction];

    [alertController addAction:okAction];

    [alertController addAction:showAction];

 

    //        NSLog(@"%@",[userDefaults objectForKey:@"appVersion"]);

    //        NSLog(@"%@",[userDefaults objectForKey:@"userOptChoose"]);

    //        NSLog(@"%@",[userDefaults objectForKey:@"theDays"]);

 

    [VC presentViewController:alertController animated:YES completion:nil];

 

    }else{

        #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0

        alertViewTest = [[UIAlertView alloc] initWithTitle:@"致开发者的一封信" message:@"有了您的支持才能更好的为您服务,提供更加优质的,更加适合您的App,当然您也可以直接反馈问题给到我们" delegate:self cancelButtonTitle:@"????残忍拒绝" otherButtonTitles:@"????好评赞赏",@"????我要吐槽", nil];

        [alertViewTest show];

        #endif

    }

 

}

 

#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0

 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

 

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    //当前时间戳的天数

    NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];

    int daySeconds = 24 * 60 * 60;

    NSInteger theDays = interval / daySeconds;

    //当前版本号

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

    float appVersion = [[infoDictionary objectForKey:@"CFBundleShortVersionString"] floatValue];

    //userDefaults里版本号

    float udAppVersion = [[userDefaults objectForKey:@"appVersion"] intValue];

    //userDefaults里用户选择项目

    int udUserChoose = [[userDefaults objectForKey:@"userOptChoose"] intValue];

    //userDefaults里用户天数

    int udtheDays = [[userDefaults objectForKey:@"theDays"] intValue];

 

    //当前版本比userDefaults里版本号高

    if (appVersion>udAppVersion) {

        [userDefaults setObject:[NSString stringWithFormat:@"%f",appVersion] forKey:@"appVersion"];

    }

 

    switch (buttonIndex) {

        case 0: //残忍的拒绝

        if (udUserChoose30) {

            [userDefaults setObject:@"3" forKey:@"userOptChoose"];

            [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];

        }else{

            [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)(theDays-udtheDays+3)] forKey:@"userOptChoose"];

        }

        break;

        case 1:{ //好评

            [userDefaults setObject:@"1" forKey:@"userOptChoose"];

            [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];

            NSString *str = [NSString stringWithFormat:

            @"https://itunes.apple.com/cn/app/id%@?mt=8",

            self.myAppID ];

 

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

        }

        break;

        case 2:{ //不好用,我要提意见

            [userDefaults setObject:@"2" forKey:@"userOptChoose"];

            [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];

            NSString *str = [NSString stringWithFormat:

            @"https://itunes.apple.com/cn/app/id%@?mt=8",

            self.myAppID ];

 

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

        }

        break;

 

        default:

        break;

        }

    //    NSLog(@"%@",[userDefaults objectForKey:@"appVersion"]);

    //    NSLog(@"%@",[userDefaults objectForKey:@"userOptChoose"]);

    //    NSLog(@"%@",[userDefaults objectForKey:@"theDays"]);

 

}

 

#endif

 

 

@end

具体使用方法如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

#import "ViewController.h"

#import "LBToAppStore.h"

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

 

-(void)viewDidAppear:(BOOL)animated{

 

    //用户好评系统

    LBToAppStore *toAppStore = [[LBToAppStore alloc]init];

    toAppStore.myAppID = @"1067787090";

    [toAppStore showGotoAppStore:self];

 

}

 

 

@end

转载于:https://my.oschina.net/u/2361492/blog/677032

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值