Dec 072010
 

This tutorial will show you how to add a “rate it” button to your iPhone app using Corona.

This is one of the easiest things you can possibly add to your app but I have found it does make an impact on the number of ratings and reviews you get over time.

Here’s what my button looks like in Happy Doodle Sushi Smile -

Now, to add your own button you are going to want to follow the VERY basic instructions below;

STEP ONE: Create an image for your button and whack that in your project folder.

STEP TWO: Even though your application hasn’t been submitted yet (unless this is an update) if you have created it in iTunes Connect it will still have an App ID. Get that and keep it handy for a minute.

STEP THREE: Open your main.lua file or if you are using multiple scenes/screens thanks to director, (I have a tutorial for that if anyone needs it, I’m not linking to it right now because I’m lazy. It’s here, though,) open your menu.lua or whatever you are using for your main menu – then place this code above or below your other buttons, such as Start, OpenFeint or what have you;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local ratebutton = display.newImage ("rateit.png")
ratebutton.x = 164
ratebutton.y = 390
localGroup:insert(ratebutton)
--> Adds the Rate It button

local function doRating(event)
if event.phase == "ended" then
local url = "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa"
url = url .. "/wa/viewContentsUserReviews?"
url = url .. "type=Purple+Software&id="
url = url .. "404532572"

system.openURL(url)
end
end

ratebutton:addEventListener("touch", doRating)
--> Adds the Rate It functionality. Be sure to change the APP ID to your OWN; right now it's mine so you can see a working example if you like, but obviously in your own app you'll want it to go to the app's rating/review page!

It is that easy!

Using the text above you will have a button that goes directly to the rate/review page for your app, very convenient!

As usual, any questions or comments just let me know here in the comments section, on Facebook if I’m your FB Buddy (lol) or on Twitter if you are one of the people who’s been kind enough to follow me. ^-^;

Peach Pellen :)

PS – I’m going to be busy, busy, busy this week with cleaning my house for Christmas, doing Christmas shopping tomorrow, (you’d think it’d be faster when you’re a poor person but it’s not, it takes twice as long to sniff out bargains that still make nice little gifts for loved ones,) sorting out the aircon on Thursday, going to the dentist and a whole lot of other things. My points in that little rambling, run on sentence was that you likely wont see another tutorial this week but that I plan to do one next week – I don’t know what on yet – I was thinking music/sound on/off – but we’ll see. Hit me up if you have a suggestion.

In December I also hope to start on what I’ll probably call my “Corona For Noobs” mini series which will have, hopefully, a whole lot of handy info to help a few folks I know who are looking to move into Corona and Lua but are currently feeling a bit lost and unsure about where to start. Stay tuned!

Like this post? Subscribe to the monthly newsletter!

 

  51 Responses to “How To Add A “Rate It” Button To Your iPhone App”

  1. Hi,

    You tell me what the “type” is referencing in the URL “purple+software” ?

    I searched on Google and everyone who asks about links to the App Store reviews, seems to have this type in their URL.

    Dave

    • Honestly Dave, I have no idea. We discussed this on the forum recently too. It’s just how it is. (I’ve wondered if it was a way to differentiate between apps, videos and music but that still seems odd to me.)
      So, I can’t tell you – I just know it’s how it’s done. Sorry!

  2. It will open the app store on device but the application wont be found; it will work the moment your app appears in the store.

    So long as you very carefully paste your app ID in the URL it will be fine. (Done it a million times ;))

  3. Thanks. I understand it not working on Corona Simulator but should it work on the XCode simulator? Also does it work before actually uploading the app?

  4. First of all thanks for being. Secondly what is the meaning of “type=Purple+Software&id=” in your code?

  5. Hey, this works great!

    I have one question thou, is there any way to get back to the app from the review page without the app restarting or closing down?

  6. Hi Peach,

    Is it possible to create something like a pop up button when the user reaches de end of the app? Not just the button expecting to be pressed, the one that the user is forced to either rate or tap “no thanks!”!

    Thanks,
    Gustavo

  7. Hi Chris,

    No, I can’t see why that would happen. If you want to upload your project somewhere so I can check it out I’d be willing to have a look, but there’s no reason the code shouldn’t work, I have used it recently, multiple times, without issue.

  8. Hey Peach,

    There is no reason for that, i fixed that. Tired to repost the button, got the button to show up with the other buttons. But when I clicked on the rate button it started to play like the play button. Im all backwards lol. But when i tired to add the function to the rate then my buttons disappeared. So anymore idea’s? Ill keep messing with it see if i can figure it out.

    Thank you as always,

    Chris

  9. Hey Chris,

    No worries – WordPress is sometimes a bit of a pain like that. (Mine wont accept Lua tags in comments, only code tags – been looking for a way to fix that, though.)

    To me the first thing that really stands out as a problem is that you say;

    1
    ui = ui

    but have the require “ui” part commented out.

    Is there a reason for that? It would create a fair number of issues in the code that follows it.

    Let me know :)

    Peach

  10. Sorry i tagged the code, not sure why it didn’t show up right.

  11. Below is the code. I added the button in every aspect that I should be adding it. I can’t get anything. Hopefully you can pull some magic off like normal and help me out. Also off topic, before adding this button or even trying, my open feint was working correctly. After adding it and then deleting the button because it doesn’t work. My open feint stop working any idea on that. Thanks in advance with the help.

    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
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    local ui = ui --require("ui")
    local ofTween
    local playTween
    local rateTween
    local isLevelSelection = false
       
        -- AUDIO
        local tapSound = audio.loadSound( "tapsound.wav" )
       
        local drawScreen = function()
           
            -- BACKGROUND IMAGE
            local backgroundImage = display.newImage( "mainmenu.png", 480, 320 )
            backgroundImage.x = 240; backgroundImage.y = 160
           
            menuGroup:insert( backgroundImage )
           
           
           
            local ofBtn
           
            -- OPENFEINT BUTTON
            local onOFTouch = function( event )
                if event.phase == "release" and not isLevelSelection and ofBtn.isActive then
                   
                    audio.play( tapSound )
                   
                    print( "OpenFeint Button Pressed." )
                   
                    local openfeint = require "openfeint"

                    local of_product_key = "Qa1G7KpYs6qnhPpXZvNZ7g"
                    local of_product_secret = "2ufUFjxw4cvn1P1Dx8MM2Azp3ZI1BPorYoTWwks771w"
                    local of_app_id = "351952"
                    local display_name = "Zombie Slash"

            openfeint.init ("Qa1G7KpYs6qnhPpXZvNZ7g", "2ufUFjxw4cvn1P1Dx8MM2Azp3ZI1BPorYoTWwks771w", "Zombie Slash", "351952")
                    --Will display OpenFeint dashboard when uncommented (if OpenFeint was properly initialized in main.lua)
                    openfeint.launchDashboard()
                   
                end
            end
           
            ofBtn = ui.newButton{
                defaultSrc = "openfeint_btn.png",
                defaultX = 50,
                defaultY = 61,
                overSrc = "openfeint_btn.png",
                overX = 50,
                overY = 61,
                onEvent = onOFTouch,
                id = "OpenfeintButton",
                text = "",
                font = "Helvetica",
                textColor = { 255, 255, 255, 255 },
                size = 16,
                emboss = false
            }
           
            ofBtn:setReferencePoint( display.BottomCenterReferencePoint )
            ofBtn.x = 150 ofBtn.y = 400
           
            menuGroup:insert( ofBtn )
           
            -- PLAY BUTTON
            local playBtn
           
            local onPlayTouch = function( event )
                if event.phase == "release" and not isLevelSelection and playBtn.isActive then
                   
                    audio.play( tapSound )
                   
                    -- Bring Up Level Selection Screen
                   
                    isLevelSelection = true
                    ofBtn.isActive = false
                    ofBtn.isActive = false
                   
                    local shadeRect = display.newRect( 0, 0, 1024, 768 )
                    shadeRect:setFillColor( 0, 0, 0, 255 )
                    shadeRect.alpha = 0
                    menuGroup:insert( shadeRect )
                    transition.to( shadeRect, { time=100, alpha=0.85 } )
                   
                    local levelSelectionBg = display.newImageRect( "levelselection.png", 240, 160 )
                    levelSelectionBg.x = 240; levelSelectionBg.y = 160
                    levelSelectionBg.isVisible = false
                    menuGroup:insert( levelSelectionBg )
                    timer.performWithDelay( 200, function() levelSelectionBg.isVisible = true; end, 1 )
                   
                    local level1Btn
                   
                    local onLevel1Touch = function( event )
                        if event.phase == "release" and level1Btn.isActive then
                            audio.play( tapSound )
                            --audio.stop( backgroundSound )
                            --audio.dispose( backgroundSound ); backgroundSound = nil
                           
                            level1Btn.isActive = false
                            director:changeScene( "loadlevel1" )
                        end
                    end
                   
                    level1Btn = ui.newButton{
                        defaultSrc = "level1btn.png",
                        defaultX = 114,
                        defaultY = 114,
                        overSrc = "level1btn.png",
                        overX = 114,
                        overY = 114,
                        onEvent = onLevel1Touch,
                        text = "",
                        font = "Helvetica",
                        textColor = { 255, 255, 255, 255 },
                        size = 16,
                        emboss = false
                    }
                   
                    level1Btn.x = 180 level1Btn.y = 175
                    level1Btn.isVisible = false
                   
                    menuGroup:insert( level1Btn )
                    timer.performWithDelay( 200, function() level1Btn.isVisible = true; end, 1 )
                   
                    local level2Btn
                   
                    local onLevel2Touch = function( event )
                        if event.phase == "release" and level2Btn.isActive then
                            audio.play( tapSound )
                            --audio.stop( backgroundSound )
                            --audio.dispose( backgroundSound ); backgroundSound = nil
                           
                            level2Btn.isActive = false
                            director:changeScene( "loadlevel2" )
                        end
                    end
                   
                    level2Btn = ui.newButton{
                        defaultSrc = "level2btn.png",
                        defaultX = 114,
                        defaultY = 114,
                        overSrc = "level2btn.png",
                        overX = 114,
                        overY = 114,
                        onEvent = onLevel2Touch,
                        id = "Level2Button",
                        text = "",
                        font = "Helvetica",
                        textColor = { 255, 255, 255, 255 },
                        size = 16,
                        emboss = false
                    }
                   
                    level2Btn.x = level1Btn.x + 117; level2Btn.y = 175
                    level2Btn.isVisible = false
                   
                    menuGroup:insert( level2Btn )
                    timer.performWithDelay( 200, function() level2Btn.isVisible = true; end, 1 )
                   
                    local closeBtn
                   
                    local onCloseTouch = function( event )
                        if event.phase == "release" then
                           
                            audio.play( tapSound )
                           
                            -- unload level selection screen
                            display.remove( levelSelectionBg ); levelSelectionBg = nil
                            display.remove( level1Btn ); level1Btn = nil
                            display.remove( level2Btn ); level2Btn = nil
                            display.remove( shadeRect ); shadeRect = nil
                            display.remove( closeBtn ); closeBtn = nil
                           
                            isLevelSelection = false
                            playBtn.isActive = true
                            ofBtn.isActive = true
                        end
                    end
                   
                    closeBtn = ui.newButton{
                        defaultSrc = "closebtn.png",
                        defaultX = 30,
                        defaultY = 30,
                        overSrc = "closebtn-over.png",
                        overX = 30,
                        overY = 30,
                        onEvent = onCloseTouch,
                        id = "CloseButton",
                        text = "",
                        font = "Helvetica",
                        textColor = { 255, 255, 255, 255 },
                        size = 16,
                        emboss = false
                    }
                   
                    closeBtn.x = 123; closeBtn.y = 240
                    closeBtn.isVisible = false
                   
                    menuGroup:insert( closeBtn )
                    timer.performWithDelay( 201, function() closeBtn.isVisible = true; end, 1 )
                   
                end
            end
           
            playBtn = ui.newButton{
                defaultSrc = "play_btn.png",
                defaultX = 70,
                defaultY = 85,
                overSrc = "play_btn.png",
                overX = 70,
                overY = 85,
                onEvent = onPlayTouch,
                id = "PlayButton",
                text = "",
                font = "Helvetica",
                textColor = { 255, 255, 255, 255 },
                size = 16,
                emboss = false
            }
           
            playBtn:setReferencePoint( display.BottomCenterReferencePoint )
            playBtn.x = 240 playBtn.y = 500
           
            menuGroup:insert( playBtn )
           
            -- SLIDE PLAY AND OPENFEINT BUTTON FROM THE BOTTOM:
            local setPlayBtn = function()
                playTween = transition.to( playBtn, { time=100, x=240, y=308 } )
               
            local setOfBtn = function()
                ofTween = transition.to( ofBtn, { time=100, x=150, y=308 } )
            end
               
                ofTween = transition.to( ofBtn, { time=900, y=308, onComplete=setOfBtn, transition=easing.inOutExpo } )
            end
           
                playTween = transition.to( playBtn, { time=900, y=308, onComplete=setPlayBtn, transition=easing.inOutExpo } )
            end
  12. Wow OK so the key issue is actually with how you’re adding the button. (That’s not a guess, by the way – just logic.) – Provided it was working fine on your device before you implemented this, that is.

    If that’s the case, post some code for me to look at and I’ll see if there’s any obvious problems.

    Peach

  13. Ok when i just added the button, it showed up. But the other buttons did not. So i preceded with it and added the function, then did a trial on my iPhone and it would open but then it would crash within 2 seconds of being opened. So you guess is as good as mine.

  14. Im trying to insert this button on my menu, but when i do. All my other buttons disappear, and no errors show up in the terminal or debugger. Any suggestions?

    • That’s very odd.

      Try adding just the image for the button, no function – see if it shows up then. If so, add the function again carefully and see if it all disappears.

      Let me know which seems to be the culprit, button or function.

  15. I don’t believe you could, no. (It happens outside the app so you couldn’t track it.)

    You could remove it once it was pressed or whatnot, but really, I like having it there – updated versions need new ratings and also some people will click but not rate and I like to remind them ;)

    Peach

  16. Once the app is rated, can you make it so the button disappears, or would you just direct it to a similar page but without the button using director?

  17. No worries; check the terminal in future ;) It would have shown up as an error.

    Peach :)

  18. You’re right! I don’t know why I didn’t see that! Duh…

    thank you!

  19. Nothing has changed but your code is wrong.

    You have created the button and called it “rateit” however you are trying to add the listener to an object called “rateitbutton” which doesn’t exist.

    Change rateitbutton:addEventListener(“touch”, doRating) to rateit:addEventListener(“touch”, doRating) and it should work fine.

    Peach :)

  20. Peach,

    Has anything changed with the rate it code? I used it on my first game and it works great. I tried to use it on my current game and when I build it gives an error. I can place the button but when I add the coding to do the rating it gives and error. my code is below

    local rateit = display.newImage (“rateit.png”)
    rateit.x = 225
    rateit.y = 55
    rateit.xScale = .5
    rateit.yScale = .5
    localGroup:insert(rateit)
    –>This places the rateit button

    local function doRating(event)
    if event.phase == “ended” then
    local url = “itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa”
    url = url .. “/wa/viewContentsUserReviews?”
    url = url .. “type=Purple+Software&id=”
    url = url .. “453641732″

    system.openURL(url)
    end
    end

    rateitbutton:addEventListener(“touch”, doRating)
    –> Adds the Rate It functionality. Be sure to change the APP ID to your OWN;

  21. No worries, glad you’ve got it working now :)

  22. I didn’t try since you had the word button on yours I changed mine as you did. My .png was already called “rateit.png” but I was not using button in my regular code, just rate it to insert my graphic. I added button when I saw your posting and left it off in one place by mistake and it was giving me a Director error. It is working fine now and I have tested it on my Ipod Touch.

    Thanks for such a great Tutorial!!

    Michelle

  23. What happens when you use the code EXACTLY as it appears?

  24. I left the word button off of one of the words…. operator error!!

  25. Did you modify the code at all? In your code are you currently using localGroup?

  26. Thanks Peach,

    I wasn’t trying to use it in the simulator. I was just trying to add the code. After I added to my file it gave me a director ERROR.

  27. What error message? What “stop”? A crash or a printed error?

    I already explained that it wont work in the simulator because it is designed to open the app store on your PHONE, where it then lets people rate your app. Remember?

  28. I get an error message when I enter the data in simulator. It stops my program.

  29. Will this work in the simulator to test? I’m getting an director class error message.

    • No, it wont – It doesn’t work on the simulator because it opens the App Store on your iPhone, which the sim doesn’t do.

  30. Thanks for this, nice and easy to implement.

    I do have a quick question though. I tested it with your app ID and it worked… I was sent to exactly where I could rate your app in the app store. However, I couldn’t find any way to see what app I would be reviewing. No name, no way to tab over to a description or anything.

    I just thought that was a little weird. I never actually clicked a “rate this” prompt from one of the many games I own so I don’t know if this is how it always is.

    • Hey,

      This is a standard thing – because it will be coming from your game, people know what they are reviewing :)

      Peach

  31. Does this code need to be different since I am using Director? If so, what changes do I need to make?

    Thanks!

    • It should work just fine without any changes with Director :)

      The only thing that you need to change is the number (bottom line) to your own :)

  32. What is the point in this (below code) ??

    local url = “itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa”
    url = url .. “/wa/viewContentsUserReviews?”
    url = url .. “type=Purple+Software&id=”
    url = url .. “404532572″

    Why not just do :

    url = “itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa” .. “/wa/viewContentsUserReviews?” .. “type=Purple+Software&id=” .. “404532572″

    • Why not, indeed.

      This post was written less than a month after I wrote my first lines of Lua, so certainly, it is not the fastest was of doing things – however people asked me how I had done my rate button and I was happy to share it with them :)

      Peach

  33. OK. THANKS

  34. You caught me right before going offline for a bit; good timing!

    http://techority.com/ssrock.png

    That screen shot shows you where the App ID is.

    You can get to the screen by logging into iTunes Connect, choosing Manage Applications and then clicking on the App you want the ID of.

    Hope that helps!

    Peach :)

  35. Would be very nice to see a screenshot, so I’m sure (is it the same number as the Bundle Seed ID?).

    I quickly understand when you explain long…:)
    Thanks

  36. Hello,
    appID is not clear for me, sorry… where do I find the app ID? Is it the one I see in the Provisionning portail (cf. App IDs) or is it still another one? (I can’t see where in the iTunes Connect process I can get an app ID. Post #3 and 4 disturbes me.

    Thanks a lot Peach and I wish you a very succesful way for your work.

    • Hi Jan,

      In iTunes Connect one you have added your application, (you don’t have to upload it, just add it in iTunes Connect) you will be able to go, from the page you get to when logged in, “Manage My Applications” then from there click the App. It will have the App ID near the SKU number you chose.

      If you cannot find it post here again and I will take a screenshot and upload it for you showing where to look :)

      Peach

  37. Hey Peach!

    Just wondering how you do get the appid before upload?

    Do you finalize the app after you created the app in itunes connect and then take the app id from there right before upload?

    Cheers!

    • Hey :)

      You’re correct, you simply take it from there and add it right before compiling the app for upload.

      Apologies, I could have made it clearer!

  38. Hi PP,
    That was an amazingly good tutorial. Why do you not post the code in a file under the Corona Samples section as well?

    cheers,

    J

    • Hey Jayant :)

      I haven’t currently posted any code there, although Carlos did ask me for a link to my tutorials – I must get back to him on that.

      I might in the future, although I’d prefer to set up a proper tutorial app with them, rather than just a code snippet; if I get around to that I’ll certainly look at it.

      That and most of my tutorials already have tutorials up at Corona; these are just kind of simplified versions ^-^;

      Peach Pellen :)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.