Twitter implementation. in login of iPhone application - iphone

I am new in twitter implementation, in my application there is one login screen, I want to give an option of twitter login also ,means user can also login from his twitter account.
please give some useful tips, How to do this.

You can use TwitterShare files.
TwitterShare.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#interface TwitterShare : UIViewController
{
TWTweetComposeViewController *_tweetSheet;
}
#property (nonatomic, retain) TWTweetComposeViewController *_tweetSheet;
- (void)buildTweetSheet:(UIView*) viewOnWhichToShow;
-(void)share:(UIImage*)imageToUpload viewOnWhichToShow:(UIView*) viewOnWhichToShow;
#end
TwitterShare.m
#import <MobileCoreServices/UTCoreTypes.h>
#import "TwitterShare.h"
#import "ProgressIndicator.h"
#implementation TwitterShare
#synthesize _tweetSheet;
#pragma mark -
#pragma mark View methods
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
#pragma mark -
#pragma mark Showing Tweet Sheet
- (void)buildTweetSheet:(UIView*) viewOnWhichToShow
{
/* make instance of tweet sheet */
_tweetSheet = [[TWTweetComposeViewController alloc] init];
/* Specify the completion handler */
TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result)
{
[self dismissModalViewControllerAnimated:YES];
NSString *info;
if(result == TWTweetComposeViewControllerResultDone)
{
info = [NSString stringWithFormat:#"Saved"];
ProgressIndicator *indicator = [[ProgressIndicator alloc]init];
[indicator tweetSuccessOrFail:info view:viewOnWhichToShow];
[indicator release];
indicator = nil;
}
else if(result == TWTweetComposeViewControllerResultCancelled)
{
// statements if tweet sheet cancelled.
}
[_tweetSheet release];
_tweetSheet = nil;
};
[_tweetSheet setCompletionHandler:completionHandler];
}
#pragma mark -
#pragma mark Share to Twitter
-(void)share:(UIImage*)imageToUpload viewOnWhichToShow:(UIView *)viewOnWhichToShow
{
[self setView:viewOnWhichToShow];
[self buildTweetSheet:viewOnWhichToShow];
/* add Image To _tweetSheet */
/* Show our tweet sheet */
[_tweetSheet addImage:imageToUpload];
[self presentModalViewController:_tweetSheet animated:YES ];
}

Looks like you have not visited (and bookmarked) Twitter Developers and its documentation yet :
Sign in with Twitter : https://dev.twitter.com/docs/auth/implementing-sign-twitter
SSO with iOS >= iOS5 : https://dev.twitter.com/docs/ios#Single_Sign-On

Related

make iPhone vibrate programmatically through IF Else statement [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Making the iPhone vibrate
I have two buttons. One button adds up, one button adds down. The question is when I certain number such as lets say 22 is in the text area, the phone vibrates for a certain mount of time. Here is my code for it:
What I am trying to say is IF Label Displays "22" THEN VIBRATE PHONE... The question is how do i go about writing this.. I'm still learning so any help regarding this would be much appreciated! Here is my code so far:
#import "StartCountViewController.h"
#import "AudioToolbox/AudioServices.h"
#implementation StartCountViewController
int Count=0;
-(void)awakeFromNib {
startCount.text = #"0";
}
- (IBAction)addNumber {
if(Count >= 999) return;
NSString *numValue = [[NSString alloc] initWithFormat:#"%d", Count++];
startCount.text = numValue;
[numValue release];
}
- (IBAction)vibrate {
}
- (IBAction)subtractNumber {
if(Count <= -35) return;
NSString *numValue = [[NSString alloc] initWithFormat:#"%d", Count--];
startCount.text = numValue;
[numValue release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
This is basically a duplicate of Programmatically make the iPhone vibrate
Having said that, I think your code is still going to have errors, and the syntax seems deprecated.
Here's an example. I didn't try this on an actual iphone which would be required to test the vibration, but it should work provided you add the AudioToolbox framework to your project, and of course your XIB file has the necessary connections:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (retain, nonatomic) IBOutlet UILabel *numberLabel;
- (IBAction)addNumber:(id)sender;
- (IBAction)subtractNumber:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#import "AudioToolbox/AudioServices.h"
#interface ViewController ()
{
int count;
}
#end
#implementation ViewController
#synthesize numberLabel;
- (void)viewDidLoad
{
count = 0;
[self updateCount];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setNumberLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc
{
[numberLabel release];
[super dealloc];
}
- (IBAction)addNumber:(id)sender
{
if(count >= 999) {
return [self vibrate];
}; // ignore numbers larger than 999
count++;
[self updateCount];
}
- (IBAction)subtractNumber:(id)sender
{
if(count <= -35) {
return [self vibrate];
}; // ignore numbers less than -35
count--;
[self updateCount];
}
-(void)updateCount
{
NSString *countStr = [[NSString alloc] initWithFormat:#"%d",count];
[self.numberLabel setText:countStr];
[countStr release];
}
-(void)vibrate
{
NSLog(#"I'm vibrating");
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
#end

does not submit the score in gamecenter

i want input gamecenter in my app
so i make new project "gamecenter" for test gamecenter
i referenced "http://www.youtube.com/watch?v=9avpP0hYwik" video. but
I use xcode 4.2 so delete of "autorelease"
app does not submit the score at gamecenterhelp plz :-(
my code is
viewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UILabel *scoreText;
int *scoreInt;
}
-(IBAction)subScore:(id)sender;
-(IBAction)showLeader:(id)sender;
-(IBAction)addScore:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#import <Gamekit/Gamekit.h>
#implementation ViewController
-(IBAction)subScore:(id)sender
{
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:#"1234567"];
scoreReporter.value = scoreInt;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(#"failed");
}
else
{
NSLog(#"Succeeded");
}
}];
}
-(IBAction)showLeader:(id)sender
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)addScore:(id)sender
{
scoreInt +=1;
NSString *clicks = [NSString stringWithFormat:#"%d", scoreInt];
scoreText.text = clicks;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
{
NSLog(#"Authentication Successful!");
}
else
{
NSLog(#"Authentication Failed!");
}
}];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
Are you sure your leaderboard category id is correct?
Do you get any error messages in your request blocks?
If you get no response to your asynchronous request blocks, it means gamecenter is not ready to handle your request. You need to wait for a few hours if you just created the leaderboard.

Iphone WebView links won't open in Safari

I have followed many tutorials and my links in my web view are still not opening up in safari.
I am a noob, this is my first IPhone App, so I hope I'm just missing something simple.
//
// ViewController.m
// FirstIphoneApp
//
// Created by admin on 12/2/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
#implementation ViewController
#synthesize webView;
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://somewebsite.com/iphone.html"]]];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
And here is my Header File
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UIWebViewDelegate,UIAlertViewDelegate>{
IBOutlet UIWebView *webView;
}
#property(nonatomic, retain) IBOutlet UIWebView *webView;
#end
Does the shouldStartLoadWithRequest method fire? It may be that you haven't connected the delegate in your nib file. Usually this will be connected to your view controller, or whatever file the shouldStartLoadWithRequest method is found in.

IOS Developer, working on a basic MPMoviePlayer app. Cant get the video to stop playing using navigationbar

Hi i am designing a basic iPhone/iPad app that has a UINavigationController. The user clicks on the table row and it opens up a video in full screen. This works well and plays the video. however when you click on the navigation bar to go back to the table on the rootViewController the video keeps playing the audio in the background. Any ideas?
// RevoLix_HDAppDelegate.h
// RevoLix HD
//
// Created by Rob Hartley on 8/6/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#class UrologyViewController;
#interface RevoLix_HDAppDelegate : NSObject <UIApplicationDelegate> {
UrologyViewController *urologyViewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
RevoLix_HDAppDelegate.m
// RevoLix HD
//
// Created by Rob Hartley on 8/6/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RevoLix_HDAppDelegate.h"
#import "PlayerViewController.h"
#import "UrologyViewController.h"
#implementation RevoLix_HDAppDelegate
#synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//PlayerViewController *vc = [[PlayerViewController alloc] init];
//[[self window]setRootViewController:vc];
urologyViewController = [[UrologyViewController alloc] init];
//create an instance of a UINavigationController, its stack contains only itemsViewController
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:urologyViewController];
[urologyViewController release];
[[self window]setRootViewController:navController];
[navController release];
[_window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
UrologyViewController.h
// RevoLix HD
//
// Created by Rob Hartley on 8/7/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PlayerViewController.h"
# class PlayerViewController;
#interface UrologyViewController : UITableViewController {
NSMutableArray *allVideos;
}
#end
UrologyViewController.m
// RevoLix HD
//
// Created by Rob Hartley on 8/7/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "UrologyViewController.h"
#import "UrologyVideos.h"
#import "PlayerViewController.h"
#implementation UrologyViewController
- (id)init
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
[[self navigationItem] setTitle:#"Urology"];
}
allVideos = [[NSMutableArray alloc] init];
[allVideos addObject:[UrologyVideos fieldVideo]];
[allVideos addObject:[UrologyVideos strictureVideo]];
return self;
}
/*- (id)initWithStyle:(UITableViewStyle)style
{
return [self init];
}*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int numberOfRows = [allVideos count];
return numberOfRows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//create an instance of UITableViewCell, with default appearance
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"UITableViewCell"] autorelease];
//set the text on the cell with the title of the video that is at the nth idex of possessions, where n = row this cell will appear in on the tableview
[[cell textLabel] setText:[[allVideos objectAtIndex:[indexPath row]] videoTitle]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PlayerViewController *playerViewController = [[[PlayerViewController alloc] init] autorelease];
// Give detail view controller a pointer to the possession object in this row
[playerViewController setSelectVideo:[allVideos objectAtIndex:[indexPath row]]];
// Push it onto the top of the navigation controller's stack
[[self navigationController] pushViewController:playerViewController
animated:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
-(void)dealloc
{
[allVideos release];
[super dealloc];
}
#end
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#class UrologyVideos;
#interface PlayerViewController : UIViewController {
MPMoviePlayerViewController *moviePlayer;
UrologyVideos *selectVideo;
}
#property (nonatomic,retain) UrologyVideos *selectVideo;
#end
PlayerViewController.m
// RevoLix HD
//
// Created by Rob Hartley on 8/6/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "PlayerViewController.h"
#import "UrologyVideos.h"
#implementation PlayerViewController
#synthesize selectVideo;
- (id)init
{
return [super initWithNibName:#"PlayerViewController" bundle:nil];
}
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle
{
return [self init];
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self navigationItem] setTitle:[selectVideo videoTitle]];
}
- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:[selectVideo videoFileName] ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[[self view] addSubview:[moviePlayer view]];
float halfHeight = [[self view]bounds].size.height;
float width = [[self view] bounds].size.width;
[[moviePlayer view] setFrame:CGRectMake(0, 0, width, halfHeight)];
}
- (void)dealloc
{
[selectVideo release];
[moviePlayer release];
[MPMoviePlayerViewController release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
[selectVideo release];
selectVideo = nil;
[moviePlayer release];
moviePlayer = nil;
[MPMoviePlayerViewController release];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#end
Apple explains that video playback may be set to use "your application’s audio session by default, but can be configured to use a system-supplied audio session."
If you check the audio documentation, you will find you can setup behavior to stop or keep playing music if application goes to background (typically, to obtain the iPod player behavior). That's where you should set the proper application variable.

Showing ads on every view automatically in iPhone

I'm implementing Mobclix in my app, and when following the instructions, it tells us to properly release and dealloc the adview. It also tells us that when the view appears, you should call refreshAds and when it disappears you should pause refresh ads:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.adView resumeAdAutoRefresh];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.adView pauseAdAutoRefresh];
}
#implementation RootViewController
- (void)viewDidUnload {
[self.adView cancelAd];
self.adView.delegate = nil;
self.adView = nil;
}
- (void)dealloc {
[self.adView cancelAd];
self.adView.delegate = nil;
self.adView = nil;
[super dealloc];
}
#end
My question is that I have a lot of view controllers, so it would be inconvenient to implement these things on each view. Is there anyway I can call these methods in one place and have it work for all views?
What you can do is subclass UIViewController and have all your viewControllers to inherit these things.
So basically you could have AdsViewController.h wich will look like
#import <Foundation/Foundation.h?
#interface AdsViewController: UIViewController {
}
#property (nonatomic, retain) <#AdsViewType#> *adsView;
#end
and your AdsViewController.m will have to look pretty much like this
#import "AdsViewController.h"
#implementation AdsViewController
#synthesize adsView = _adsView;
- (id)init {
self = [super init];
if (self) {
_adsView = [[<#AdsViewType#> alloc] init];
_adsView.delegate = self;
}
return self;
}
- (void)viewDidUnload {
[self.adView cancelAd];
self.adView = nil;
[super viewDidUnload];
}
- (void)dealloc {
[self.adView cancelAd];
self.adsView = nil;
[super dealloc];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.adView resumeAdAutoRefresh];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.adView pauseAdAutoRefresh];
}
#end
After this have all your viewControllers to subclass this instead of UIViewController. Hope this helps.