Twitter Integration in Cocos2d-iPhone - ios

I am developing a game in which i have to post scores on my Facebook and twitter a/c.
I have written this code but it not working. It's neither giving any error nor any popup for posting something .
- (void) SLComposeViewControllerButtonPressed: (id) sender{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
AppDelegate * myDelegate = (((AppDelegate*) [UIApplication sharedApplication].delegate));
NSString *string = [NSString stringWithFormat:#"Just scored %d. ", 10];
SLComposeViewController*fvc = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[fvc setInitialText:string];
[[myDelegate navController] presentViewController:fvc animated:YES completion:nil];
}
Please give me valid solution of this problem.

CCDirector is a subclass of UIViewController in iOS. So it can be used for presenting modal viewControllers.
[[CCDirector sharedDirector] presentViewController:fvc animated:YES completion:nil];
Update: Here is a DOC
#ifdef __CC_PLATFORM_IOS
#define CC_VIEWCONTROLLER UIViewController
#elif defined(__CC_PLATFORM_MAC)
#define CC_VIEWCONTROLLER NSObject
#endif
#interface CCDirector : CC_VIEWCONTROLLER

Related

Video player with play/pause controls and pictureInPicture like in Safari

How can I use a video player like this screenshot and include it in my Objective-C application:
I took it in Safari on iPad air2 simulator with IOS9, and it was playing a live broadcast ..
It looks like MPMoviePlayerViewController but it is formally deprecated in iOS 9 ..
Also doesn't look like AVPictureInPictureController or AVPlayerViewController because they don't have any control buttons ..
So, I'm asking how can I include in my app such player (contain done/play/pause/pictureInPicture) buttons and is supported in IOS9
Thanks in advance ..
Thanks a lot to Luan Nguyen ..
I was able to include the player from the screenshot in my application using AVPlayerViewController and showsPlaybackControls = YES, allowsPictureInPicturePlayback = YES
Here is the full sample code :
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#interface ViewController ()<AVPlayerViewControllerDelegate>{
AVPlayerViewController *_AVPlayerViewController;
}
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
// create a movie player
NSURL *url = [NSURL URLWithString:#"http://38.96.175.119:1935/aletejahtv/aletejahtv3/playlist.m3u8"];
_AVPlayerViewController = [AVPlayerViewController new];
_AVPlayerViewController.delegate = self;
_AVPlayerViewController.showsPlaybackControls = YES;
_AVPlayerViewController.allowsPictureInPicturePlayback = YES;
_AVPlayerViewController.videoGravity = AVLayerVideoGravityResizeAspect;
_AVPlayerViewController.player = [AVPlayer playerWithURL:url];
[_AVPlayerViewController.player play];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:_AVPlayerViewController animated:YES completion:nil];
});
}
#end

Admob Interstitial Cocos2d Objective C

i'm searching on google but i only find the way to integrate the AdMob Banner View on my app in Cocos2d. Now I need to put the full screen AdMob interstitial and i don't find the way to do it :. Please Help me, how i can do it??
I'm not sure what source code i need to post... I would like to show the interstitial when the app startup and when there is the game over.
I already tried this
but it gave me some error.
In AppDelegate.h, add GADInterstitialDelegate
#interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate, GADInterstitialDelegate>
{
}
-(void)showAdmobFullScreenAds;
#end
#define App ((AppController *)[[UIApplication sharedApplication] delegate])
In AppDelegate.m
-(void)showAdmobFullScreenAds
{
GADInterstitial *interstitial_ = [[GADInterstitial alloc] init];
interstitial_.adUnitID = #"ca-app-pub-YOUR_ID";
interstitial_.delegate = self;
[interstitial_ loadRequest:[GADRequest request]];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
[interstitial presentFromRootViewController:[CCDirector sharedDirector]];
}
// In GameOver class, add #import "AppDelegate.h" then use below function
[App showAdmobFullScreenAds];

Back Button Support On Android for Cocos2d v3.x via Apportable

As described in Apportable Doc, I have created a subclass of UIResponder named AndroidButtonManager to have support for hardware button tap events (Back, Home button tap) in my current cocos2d-iPhone v3.1 project. Here are the codes of interface and implementation files
AndroidButtonManager.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#interface AndroidButtonManager :UIResponder<UIApplicationDelegate>{
}
+(instancetype) sharedManager;
#end
and AndroidButtonManager.m
#import "AndroidButtonManager.h"
#implementation AndroidButtonManager
+(instancetype)sharedManager
{
static AndroidButtonManager* sharedManager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc]init];
});
return sharedManager;
}
-(instancetype)init{
if (self = [super init]) {
[self canBecomeFirstResponder];
}
return self;
}
#ifdef ANDROID
// ----------------------------------------------------------------
// OVER RIDING PARENT CLASS METHOD
// ----------------------------------------------------------------
-(BOOL)canBecomeFirstResponder
{
[[AlertManager sharedManager] showAlertWithHeading:#"canBecomeFirstResponder" andMessage:#"AndroidButtonManager"];
return YES;
}
- (void)buttonUpWithEvent:(UIEvent *)event
{
[[AlertManager sharedManager] showAlertWithHeading:#"buttonUpWithEvent" andMessage:#""];
switch (event.buttonCode)
{
case UIEventButtonCodeBack:
[[AlertManager sharedManager] showAlertWithHeading:#"Back Button" andMessage:#"Home Button touched , going to transit to Menu Layer"];
break;
case UIEventButtonCodeMenu:{
[[AlertManager sharedManager] showAlertWithHeading:#"Home Button" andMessage:#"Home Button touched , going to transit to Menu Layer"];
break;
}
default:
break;
}
}
#endif
#end
And I am creating the shared manager in AppDelegate's -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions by
#ifdef ANDROID
[AndroidButtonManager sharedManager];
#endif
I am getting alert from [[AlertManager sharedManager] showAlertWithHeading:#"canBecomeFirstResponder" andMessage:#"AndroidButtonManager"];, but the alert from [[AlertManager sharedManager] showAlertWithHeading:#"buttonUpWithEvent" andMessage:#""]; never appears as - (void)buttonUpWithEvent:(UIEvent *)event is never called.
I have tried implementing this in AppDelegate.m as specified in Apportable's Google Group.Both are not working.
Is there any example project implementing back button support in Android in Cocos2d-v3.x?
Thanks in advance.
Oh finally got it. Just need to make a category of CCDirector in which the button handling code will be executed. Here is the code of my CCDirector's category name CCDirector+ButtonManager.
Interface File CCDirector+ButtonManager.h
#import "CCDirector.h"
#interface CCDirector (ButtonManager)
- (BOOL)canBecomeFirstResponder;
#end
Implementation File CCDirector+ButtonManager.m
#import "CCDirector+ButtonManager.h"
#implementation CCDirector (ButtonManager)
#ifdef APPORTABLE
- (void)buttonUpWithEvent:(UIEvent *)event {
switch (event.buttonCode)
{
case UIEventButtonCodeBack:
// handle back button here
[self showAlertWithHeading:#"buttonUpWithEvent" andMessage:#"BACK BUTTON"];
break;
case UIEventButtonCodeMenu:
// show menu if possible.
[self showAlertWithHeading:#"buttonUpWithEvent" andMessage:#"MENU BUTTON"];
break;
default:
break;
}
}
- (BOOL)canBecomeFirstResponder {
[[AlertManager sharedManager] showAlertWithHeading:#"canBecomeFirstResponder" andMessage:#"CCDirector"];
return YES;
}
#endif
-(void)showAlertWithHeading:(NSString*)alertHeading andMessage:(NSString*)alertMessage
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:alertHeading
message:alertMessage
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alertView show];
}
#end
And initialize it in AppDelegate's -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions by
#ifdef APPORTABLE
[[CCDirector sharedDirector] becomeFirstResponder];
#endif

Twitter and Facebook integration iOS 7

I am trying to implement Twitter and Facebook into my app. Therefor I am using the integrated method in iOS, which is available since iOS 6, to do this. Under iOS 6, if there is no Facebook or Twitter configured an alarm view comes up to inform the user that he has to configure an account first to use Twitter or Facebook. The alarm view gives the user the option to jump directly to the settings of Twitter or Facebook. In iOS 7, if there is no account configured, no alarm view comes up to inform the user. Seems that has been disabled under iOS 7. So I am now inform the user myself but is there a way to point the user directly to the settings like it was under iOS 6? Or do I need to change my code under iOS 7 to get the alarm back?
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//inform the user that no account is configured with alarm view.
}
}
Just remove this line from your code and it will work correctly
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
in ios 7, Try with removing this condition, it will tells user to if there is no account configured.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{ SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
//inform the user that no account is configured with alarm view.
}
}

Direct link to app-store application in iOS 7

I have a free version of app. And there is a link to a full version in free app.
The link works fine in iOS 6. But in iOS 7 it shows a blank page.
Any help is appreciated!
The link I use:
- (void) getFull
{
[self hideAnimated];
NSString *iTunesLink = #"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=604760686&mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}
Pretty strange link you are using. I use:
http://itunes.apple.com/app/id<APP_ID>?mt=8
and everything works...
In apps supporting iOS6 and above, I suggest furthermore the use of StoreKit, so you can display your app page in the App Store without leaving your app. You can do that like this:
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[viewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)showAppWithIdentifier:(NSNumber *)identifier
{
if ([SKStoreProductViewController class]) {
SKStoreProductViewController *controller = [[SKStoreProductViewController alloc] init];
controller.delegate = self;
[controller loadProductWithParameters:#{ SKStoreProductParameterITunesItemIdentifier : identifier }
completionBlock:NULL];
[self presentViewController:controller animated:YES completion:nil];
return;
}
// Fall back to opening App Store for iOS 5.
... open the link as you are already doing
}
Try this one, it's the new syntax with iOS 7 and replace APP_ID by your application's AppID.
itms-apps://itunes.apple.com/app/idAPP_ID
You can refer to this link and this one for more information and discussion about that.

Resources