iOS game development outside of the game features things

Source: Internet
Author: User
Tags admob

As for the development of a game, how much more do we need to consider besides the function of the game?


Many, also very annoying!


But it will be easy the next time after you have done it again.


What things do we want to add to the game?


(1) Sharing function

(2) Scoring function

(3) Game Center (Gamecenter)

(4) Advertising (IAD and other ads such as AdMob)

(5) in-app purchase

(6) ...


These features are not entirely necessary and should be considered according to the situation. But for example, sharing, scoring, these features can improve the spread of a game, the display is worth every game added features.


Here's a little summary of the basic usage of each feature.

PS: This is just a summary of the use of each function, the Internet has a corresponding tutorial.


(1) Sharing function

The simplest and most straightforward approach is to use Uiactivityviewcontroller with the share feature that comes with iOS:

NSString *initialstring = @ "Smash bug! is a great app! With it! ";    Nsurl *url = [Nsurl urlwithstring:@ "https://itunes.apple.com/us/app/air-drum-*/id901397384?ls=1&mt=8"];    UIImage *showimage = [UIImage imagenamed:@ "[email protected]"];    Uiactivityviewcontroller *activityviewcontroller = [[Uiactivityviewcontroller alloc] initwithactivityitems:@[ Initialstring,url] Applicationactivities:nil];    [Self Presentviewcontroller:activityviewcontroller animated:yes completion:nil];

As for the realization of sharing to friends Circle, QQ space, etc., we can find the corresponding share code on the Internet.


(2) ratings

It is very simple and important to jump directly to the app Store after clicking on it:

NSString *str = @ "Itms-apps://ax.itunes.apple.com/webobjects/mzstore.woa/wa/viewcontentsuserreviews?type=purple+ software&id=901397384 ";    [[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];

It's OK to change the ID to your app ID when you use it.


(3) Gamecenter

This country may use relatively little, prefer to like, but in foreign countries is probably more important one way.


We have to enable Gamecenter on Itunesconnect and create the corresponding leadership and achievement.

There are corresponding tutorial on the Raywenderlich.


And for the use of the fact that there are two processes:

(1) Verify the local player, if not logged in, pop-up window login.

-(void) authenticatelocalplayer{    gklocalplayer *localplayer = [Gklocalplayer localplayer];        Localplayer.authenticatehandler = ^ (Uiviewcontroller *viewcontroller,nserror *error) {        //3        [self Setlasterror:error];                if (viewcontroller! = nil) {            [self setauthenticationviewcontroller:viewcontroller];        } else if ([Gklocalplayer localplayer].isauthenticated) {            _enablegamecenter = YES;        } else {            _enablegamecenter = NO;}}    ;}

-(void) Setauthenticationviewcontroller: (Uiviewcontroller *) authenticationviewcontroller{    if ( Authenticationviewcontroller = nil) {        _authenticationviewcontroller = Authenticationviewcontroller;        [[Nsnotificationcenter Defaultcenter] Postnotificationname:presentauthenticationviewcontroller object:self];    }}

(2) real-time transmission of scores and other data to Gamecenter

2.1 Send Achievement

Ways to create achievement achievements:


+ (Gkachievement *) Reach10achievement: (nsuinteger) numberofreach{    cgfloat percent = NUMBEROFREACH/10 * 100.0;        Gkachievement *reachachievement = [[Gkachievement alloc] initwithidentifier:ksmashbugreach10achievementid];    Reachachievement.percentcomplete = percent;    Reachachievement.showscompletionbanner = YES;    return reachachievement;    }

Send achievements


-(void) Reportachievements: (Nsarray *) achievements{    if (!_enablegamecenter) {        NSLog (@ "Local play is not Authenticated ");    }        [Gkachievement reportachievements:achievements withcompletionhandler:^ (nserror *error) {        [self setlasterror:error];}    ];}

2.2 Send score until leadership (leaderboard)


-(void) Reportscore: (int64_t) score Forleaderboardid: (NSString *) leaderboardid{    if (!_enablegamecenter) {        NSLog (@ "Local Play is not authenticated");    }        Gkscore *scorerep
In addition, we would like to click the Gamecenter button and other display Gamecenter interface:

Orter = [[Gkscore alloc] initwithleaderboardidentifier:leaderboardid]; Scorereporter.value = score; Scorereporter.context = 0; Nsarray *scores = @[scorereporter]; [Gkscore reportscores:scores withcompletionhandler:^ (nserror *error) { [self setlasterror:error];} ];}

In addition, we would like to click the Gamecenter button and other display Gamecenter interface:

-(void) Showgkgamecenterviewcontroller: (Uiviewcontroller *) viewcontroller{    if (!_enablegamecenter) {        NSLog (@ "Local Play is not authenticated");    }        Gkgamecenterviewcontroller *gamecenterviewcontroller = [[Gkgamecenterviewcontroller alloc] init];        Gamecenterviewcontroller.gamecenterdelegate = self;        Gamecenterviewcontroller.viewstate = gkgamecenterviewcontrollerstateachievements;        [Viewcontroller Presentviewcontroller:gamecenterviewcontroller Animated:yes completion:nil];}

(4) Advertising

IAD's most basic banner ads are now too simple, iOS7:

Add a line of code to the Viewcontroller to display your ad:


    Self.candisplaybannerads = YES;

and AdMob (I only use Google ads) is simple enough to register with AdMob and then download its SDK to add the SDK to the project.

Important step: Add-OBJC to linker Flag

Then it's simple, just copy the following code to Viewcontroller:


Admob [self addadmob], #pragma mark-admob-(void) addadmob{//Initialize the banner at the bottom.                                 Cgpoint origin = Cgpointmake (0.0, Self.view.frame.size.height-        Cgsizefromgadadsize (kgadadsizebanner). height);    Use predefined Gadadsize constants to define the Gadbannerview.        Self.adbanner = [[Gadbannerview alloc] Initwithadsize:kgadadsizebanner Origin:origin];    Note:edit SampleConstants.h to provide a definition for ksampleadunitid before compiling.    Self.adBanner.adUnitID = admob_id;    Self.adBanner.delegate = self;    Self.adBanner.rootViewController = self;    [Self.view AddSubview:self.adBanner]; [Self.adbanner loadrequest:[self request];}        #pragma mark Gadrequest generation-(gadrequest *) Request {gadrequest *request = [gadrequest request]; Make the request for a test ad. Put in a identifier for the simulator as well as a devices//you want to REceive test ads. Request.testdevices = @[//todo:add your Device/simulator test identifiers here.                            Your device identifier is printed to//the console, the app is launched.    GAD_SIMULATOR_ID]; return request;} #pragma mark Gadbannerviewdelegate implementation//We ve received an ad successfully.-(void) Adviewdidreceivead: ( Gadbannerview *) AdView {NSLog (@ "Received ad successfully");} -(void) AdView: (Gadbannerview *) View didfailtoreceiveadwitherror: (Gadrequesterror *) error {NSLog (@ "Failed to receive a D with Error:%@ ", [Error Localizedfailurereason]);}

Everything ok! Make changes according to the specific situation of the game!


(5) in-app purchase

This in my other blog has said, here no longer say.


OK, that's all that's written.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.