iOS game development outside of the game features things

Source: Internet
Author: User
Tags admob

For the development of a game, besides the function of the game, how many things do we need to consider?


Very much. Also very annoying!


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


Is there anything we want to add to the game?


(1) Sharing function

(2) Scoring function

(3) Game Center (Gamecenter)

(4) Advertising (iad and other advertising, for example AdMob)

(5) in-app purchase

(6)..


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


Here's a little summary of the basics of how each feature is used.

PS: This is just a summary of the post, detailed 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 to realize to share to the circle of friends, QQ space and so on. You can find the corresponding share code on the Internet.


(2) ratings

Just click to jump directly to the app Store, this very easy is also very important:

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 be used less, like more, but in foreign countries is probably a more important way.


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

There are corresponding tutorial on the Raywenderlich.


In fact, for the use of two processes:

(1) Verify the local player. If not logged in, pop-up form 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 on the Gamecenterbutton 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 on the Gamecenterbutton 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

The main banner ad for IAD is now too simple. IOS7:

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


    Self.candisplaybannerads = YES;

AdMob (I just use Google ads) is also very easy, after the AdMob register, then download its SDK to join the SDK to project.

Important step: Join-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 based on the details of the game.


(5) in-app purchase

This is a blog I have to talk about. Don't say it here.


OK, that's all that's written.

iOS game development outside of the game features things

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.