- <span style="font-size:24px;">NSString *initialString = @"Smash Bug! is a Great App! Have Fun with it!";
- NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/us/app/air-drum-*/id901397384?ls=1&mt=8"];
- //UIImage *showImage = [UIImage imageNamed:@"Default-568h@2x"];
- UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[initialString,url] applicationActivities:nil];
- [self presentViewController:activityViewController animated:YES completion:nil];</span>
至于要实现分享到朋友圈,QQ空间等,大家可以在网上找到相应的分享代码。
(2)评分
就是点击之后直接跳转到App Store,这个非常简单也非常重要:
- <span style="font-size:24px;">NSString *str = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=901397384";
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
- </span>
大家在使用时把id改成自己应用的id就ok了。
(3)GameCenter
这个国内可能用得比较少,更喜欢微信之类,但在国外恐怕还是比较重要的一个方式。
这个大家得在iTunesConnect上启用GameCenter,并创建相应的LeaderShip和Achievement。
Raywenderlich上有相应的Tutorial。
而对于使用其实就两个流程:
(1)验证本地玩家,如果没登陆,弹出窗口登陆。
- <span style="font-size:24px;">- (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;
- }
- };
- }
-
- </span>
- <span style="font-size:24px;">- (void)setAuthenticationViewController:(UIViewController *)authenticationViewController
- {
- if (authenticationViewController != nil) {
- _authenticationViewController = authenticationViewController;
- [[NSNotificationCenter defaultCenter] postNotificationName:PresentAuthenticationViewController object:self];
- }
- }
- </span>
(2)实时发送分数等数据到GameCenter
2.1发送Achievement
创建Achievement成就的方法:
- <span style="font-size:24px;">+ (GKAchievement *)reach10Achievement:(NSUInteger)numberOfReach
- {
- CGFloat percent = numberOfReach/110 * 100.0;
-
- GKAchievement *reachAchievement = [[GKAchievement alloc] initWithIdentifier:kSmashBugReach10AchievementId];
- reachAchievement.percentComplete = percent;
- reachAchievement.showsCompletionBanner = YES;
- return reachAchievement;
-
- }
- </span>
发送成就
- <span style="font-size:24px;">- (void)reportAchievements:(NSArray *)achievements
- {
- if (!_enableGameCenter) {
- NSLog(@"Local play is not authenticated");
- }
-
- [GKAchievement reportAchievements:achievements withCompletionHandler:^(NSError *error) {
- [self setLastError:error];
- }];
- }
- </span>
2.2 发送得分等到LeaderShip(排行榜)
- <span style="font-size:24px;">- (void)reportScore:(int64_t)score forLeaderboardID:(NSString *)leaderboardID
- {
- if (!_enableGameCenter) {
- NSLog(@"Local Play is not authenticated");
- }
-
- GKScore *scoreRep</span><pre name="code" class="objc"><span style="font-size:24px;">除此之外,我们还想点击GameCenter按钮之类显示GameCenter的界面:
- </span></pre><span style="font-size:24px;"><br>orter = [[GKScore alloc] initWithLeaderboardIdentifier:leaderboardID]; scoreReporter.value = score; scoreReporter.context = 0; NSArray *scores = @[scoreReporter]; [GKScore reportScores:scores withCompletionHandler:^(NSError *error) { [self setLastError:error]; }];}</span>
除此之外,我们还想点击GameCenter按钮之类显示GameCenter的界面:
- - (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)广告
iAd最基本的横幅广告现在实在是太简单了,iOS7:
在要显示广告的ViewController中添加一句代码就行:
- self.canDisplayBannerAds = YES;
而Admob(我只用Google的广告)也很简单,到Admob注册后,然后下载其SDK,添加SDK到工程。
重要一步:添加-ObjC到Linker Flag
然后就简单了,只需以下代码copy到ViewController:
- // Admob
- [self addAdmob];
-
- #pragma mark - Admob
-
- - (void)addAdmob
- {
- // Initialize the banner at the bottom of the screen.
- 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 an identifier for the simulator as well as any 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 when 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 ad with error: %@", [error localizedFailureReason]);
- }
万事OK!根据游戏的具体情况再做改动!
(5)应用内购买
这个在我另一篇blog有讲,这里就不再说。
ok,就写这么多了。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。