I am trying to create an app where I can send information from an apple watch to my ios Parent App. I have written the code for it but when I run the WatchConnectivity App, the information does not transfer between the apple watch and the parent ios app. This may be a problem with my code or it may be because for some reason the watch does not start with the app. I have to go to the simulator and click on the app to get it started. Is this why my code is not working?
InterfaceController.m
#import "InterfaceController.h"
#import <WatchConnectivity/WatchConnectivity.h>
#interface InterfaceController() <WCSessionDelegate>
#property (strong, nonatomic) WCSession *session;
#end
#implementation InterfaceController
-(instancetype)init {
self = [super init];
if (self) {
if ([WCSession isSupported]) {
self.session = [WCSession defaultSession];
self.session.delegate = self;
[self.session activateSession];
}
}
return self;
}
- (IBAction)catPressed {
[self sendText:#"cat"];
}
- (IBAction)dogPressed {
[self sendText:#"dog"];
}
- (IBAction)pandaPressed {
[self sendText:#"panda"];
}
- (IBAction)bunnyPressed {
[self sendText:#"bunny"];
}
-(void)sendText:(NSString *)text {
NSDictionary *applicationDict = #{#"emoji":text};
[self.session updateApplicationContext:applicationDict error:nil];
}
ViewController.m
#import "ViewController.h"
#import <WatchConnectivity/WatchConnectivity.h>
#interface ViewController () <WCSessionDelegate>
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
NSLog(#"HIIII");
}
}
- (void)session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)applicationContext {
NSString *text = [applicationContext objectForKey:#"text"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.textLabel setText:[NSString stringWithFormat:#"Text: %#", text]];
});
}
It turns out that I needed to open the parent app on the iPhone first to start sharing information between the iPhone and Watch. Thanks to MSU_Bulldog for suggesting this idea.
Related
The error is as below.
The Handler is being deinitialized before Link has completed or been exited. Did you forget to strongly reference the Handler object returned by Plaid.create?
The functionality is working in the native app using the LinkKit framework. In order to use all the functions in objective C we have included a wrapper on top of it which is as below and when building a native app using the wrapper I am facing the above issue.
Wrapper Code.
// LinkKitSwiftwrapper.h
#import <Foundation/Foundation.h>
#import <LinkKit/LinkKit-Swift.h>
#import <UIKit/UIActivity.h>
NS_ASSUME_NONNULL_BEGIN
#interface LinkKitSwiftWrapper : NSObject
- (void)presentPlaidLinkUsingLinkToken: (NSString *)linkToken completionHandler:(void (^)(NSArray *array))callbackServer;
#property (strong, retain, nonatomic, readwrite) id<PLKHandler> linkHandler;
#end
NS_ASSUME_NONNULL_END
//LinkKitswiftWrapper.m
#import "LinkKitSwiftWrapper.h"
#import <LinkKit/LinkKit-Swift.h>
#import <UIKit/UIKit.h>
#import <LinkKit/LinkKit.h>
#implementation LinkKitSwiftWrapper
static void (^callBackObjectServer)(NSArray *);
- (void) presentPlaidLinkUsingLinkToken: (NSString *)linkToken completionHandler:(void (^)(NSArray *array))callbackServer
{
callBackObjectServer = callbackServer;
PLKLinkTokenConfiguration* linkConfiguration = [PLKLinkTokenConfiguration createWithToken:linkToken
onSuccess:^(PLKLinkSuccess *success) {
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *result = #[#"SUCCESS", success.publicToken];
callBackObjectServer(result);
});
}];
linkConfiguration.onExit = ^(PLKLinkExit * exit) {
if (exit.error) {
NSLog(#"exit with %#\n%#", exit.error, exit.metadata);
} else {
NSLog(#"exit with %#", exit.metadata);
}
};
NSError *createError = nil;
id<PLKHandler> handler = [PLKPlaid createWithLinkTokenConfiguration:linkConfiguration
error:&createError];
self.linkHandler = nil;
if (handler) {
[handler retain]
self.linkHandler = handler;
UIViewController *vc = [LinkKitSwiftWrapper topViewController] ;
[self.linkHandler openWithContextViewController:vc];
} else if (createError) {
NSLog(#"Unable to create PLKHandler due to: %#", createError);
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *result = #[#"ERROR", createError.description];
callBackObjectServer(result);
});
}else{
NSString *errorMessage = #"Unknown error occured while trying to create a Plaid link.";
NSLog(#"%#", errorMessage);
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *result = #[#"ERROR", errorMessage];
callBackObjectServer(result);
});
}
}
+ (UIViewController *)topViewController{
return [self topViewController:[[LinkKitSwiftWrapper keyWindow] rootViewController ]];
}
+ (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController ;
}
if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self topViewController:lastViewController];
}
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController ;
return [self topViewController:presentedViewController];
}
+(UIWindow*)keyWindow
{
UIWindow *foundWindow = nil;
NSArray *windows = [[UIApplication sharedApplication]windows];
for (UIWindow *window in windows) {
if (window.isKeyWindow) {
foundWindow = window;
break;
}
}
return foundWindow;
}
#end
//Native App code
#import "ViewController.h"
#import "PlaidWrapper/LinkKitSwiftWrapper.h"
#interface ViewController ()
#end
static void (^callBackObjectServer)(NSArray *);
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)ButtonTouchUpInside:(id)sender {
[ [LinkKitSwiftWrapper new] presentPlaidLinkUsingLinkToken:#"link-sandbox-0f671f81-c144-4160-8a64-0ce51e63dbcd" completionHandler:(void (^)(NSArray* array))callBackObjectServer];
}
#end
Please help.
I have created singleton class for AVAudioPlayer. I am able to call the methods in the class and everything works fine. When the song finishes,the method (void)audioPlayerDidFinishPlaying is called which in turn suppose to call the method ' processSuccessful' in my downloadPlay.m class. But, it is not calling the method 'processSuccessful'
My codes as follows
PlayerManager.h
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#protocol ProcessDataDelegate <NSObject>
#required
- (void) processSuccessful;
#end
#interface PlayerManager : NSObject<AVAudioPlayerDelegate,AVAudioSessionDelegate>
{
id <ProcessDataDelegate> delegate;
}
+ (PlayerManager *)sharedAudioPlayer;
#property (nonatomic,assign) id <ProcessDataDelegate>delegate;
#property (nonatomic, strong) AVAudioPlayer* player;
-(void)preparesong:(NSURL *)url;
-(void)stopsong;
-(void)pause;
-(void)playsong;
-(void)prepareToPlay;
-(BOOL)isPlaying;
-(BOOL)isPlayerExist;
#end
PlayerManager.m
#import "PlayerManager.h"
#interface PlayerManager()
#end
#implementation PlayerManager
#synthesize player;
#synthesize delegate;
static PlayerManager *sharedAudioPlayer = nil;
+ (PlayerManager *)sharedAudioPlayer {
static PlayerManager *sharedAudioPlayer = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedAudioPlayer = [[self alloc] init];
});
return sharedAudioPlayer ;
}
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withOptions:(NSUInteger)flags
{
if (flags & AVAudioSessionInterruptionOptionShouldResume)
{
[self.player play];
}
}
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player
{
}
#pragma mark - AVAudioPlayerDelegate
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[[self delegate] processSuccessful];
}
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{
}
-(void)preparesong:(NSURL *)url
{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
NSError *error;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if(!self.player)
{
NSLog(#"Error creating player: %#", error);
}
self.player.delegate = self;
[self.player prepareToPlay];
}
-(BOOL)isPlayerExist
{
if (player)
return YES;
return NO;
}
-(BOOL)isPlaying
{
if (player && player.playing)
return YES;
return NO;
}
-(void)prepareToPlay
{
if (player)
[self.player prepareToPlay];
}
-(void)playsong
{
if (player)
[self.player play];
}
-(void)pause
{
if (player.playing)
[self.player pause];
}
-(void)stopsong
{
if (player)
[self.player stop];
}
#end
downloadPlay.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import "PlayerManager.h"
#interface downloadPlay: UIViewController <UITableViewDelegate,AVAudioPlayerDelegate,ProcessDataDelegate>
{
PlayerManager *protocolPlay;
}
#property (retain, nonatomic) IBOutlet UITableView *tblFiles;
......
- (void)startPlay:(id)sender;
........
#end
downloadPlay.m
import "downloadPlay.h"
#import "PlayerManager.h"
#interface downloadPlay ()
#end
#implementation downloadPlay
.....
- (void)processSuccessful
{
NSLog(#"This method suppose to be called from the method audioPlayerDidFinishPlaying - from PlayerManager");
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
protocolPlay = [[PlayerManager alloc]init];
[protocolPlay setDelegate:self];
}
- (void)startPlay
{
............
.........
NSURL *destinationURL = [self.docDirectoryURL URLByAppendingPathComponent:filename];
NSError* error = nil;
[[PlayerManager sharedAudioPlayer]stopsong];
[[PlayerManager sharedAudioPlayer ] preparesong:destinationURL ];
[[PlayerManager sharedAudioPlayer]playsong];
}
#end
In viewDidLoad method you are creating a different object by using
protocolPlay = [[PlayerManager alloc]init];
line and set the delegate of this object while you have to set the delegate of shared object.
Solution is:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[PlayerManager sharedAudioPlayer] setDelegate:self];
}
okay, So i basically followed the tutorial in this link
http://www.techotopia.com/index.php/An_iOS_7_In-App_Purchase_Tutorial
I also tried the tutorial in this one: How do you add an in-app purchase to an iOS application? but it did not work for me. I would really appreciate it if someone helps me out. I'm going to use the first link because that's the tutorial I used. It works fine for one in app purchase, BUT, how do i do it for more in app purchases? for more levels? The tutorial only teaches one, and so I try and follow the same tutorial but by changing the names, and it STILL doesn't work. The closest I got was it does purchase it, but it does not enable the button even though I connected the Outlets. Need help, the coding is provided below:
ViewController.h
enter code here#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#import "PurchaseViewController.h"
#import "SecondPurchaseViewController.h"
#interface MAGViewController : UIViewController
- (IBAction)purchaseItem:(id)sender;
#property (strong, nonatomic) IBOutlet UIButton *level2Button;
#property (strong, nonatomic) PurchaseViewController *purchaseController;
- (IBAction)SecondpurchaseItem:(id)sender;
#property (strong, nonatomic) IBOutlet UIButton *level3Button;
#property (strong, nonatomic) SecondPurchaseViewController *SecondpurchaseController;
-(void)enableLevel2;
-(void)enableLevel3;
#end
And the .m file is: (i did put the #import "PurchaseViewController.h" so it's not that and i also put the Second one as well.
- (IBAction)purchaseItem:(id)sender {
_purchaseController.productID =
#"com.example.IAP.courseone";
[self.navigationController
pushViewController:_purchaseController animated:YES];
[_purchaseController getProductInfo: self];
}
- (IBAction)SecondpurchaseItem:(id)sender {
_SecondpurchaseController.SecondproductID =
#"com.example.IAP.coursetwo";
[self.navigationController
pushViewController:_SecondpurchaseController animated:YES];
[_SecondpurchaseController getSecondProductInfo: self];
}
-(void)enableLevel2
{
_level2Button.enabled = YES;
}
-(void)enableLevel3
{
_level3Button.enabled = YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_purchaseController = [[PurchaseViewController alloc]init];
[[SKPaymentQueue defaultQueue]
addTransactionObserver:_purchaseController];
//
_SecondpurchaseController = [[SecondPurchaseViewController alloc]init];
[[SKPaymentQueue defaultQueue]
addTransactionObserver:_SecondpurchaseController];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
PurchaseViewController.h is
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#interface PurchaseViewController : UIViewController <SKPaymentTransactionObserver, SKProductsRequestDelegate>
#property (strong, nonatomic) IBOutlet UILabel *productTitle;
#property (strong, nonatomic) IBOutlet UITextView *productDescription;
#property (strong, nonatomic) IBOutlet UIButton *buyButton;
- (IBAction)buyProduct:(id)sender;
#property (strong, nonatomic) SKProduct *product;
#property (strong, nonatomic) NSString *productID;
- (void)getProductInfo:(UIViewController *)viewController;
#end
PurchaseViewController.m is:
#interface PurchaseViewController ()
#property (strong, nonatomic) MAGViewController *homeViewController;
#end
#implementation PurchaseViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//// -->
-(void)getProductInfo: (MAGViewController *) viewController
{
_homeViewController = viewController;
if ([SKPaymentQueue canMakePayments])
{
SKProductsRequest *request = [[SKProductsRequest alloc]
initWithProductIdentifiers:
[NSSet setWithObject:self.productID]];
request.delegate = self;
[request start];
}
else
_productDescription.text =
#"Please enable In App Purchase in Settings";
}
//
//
#pragma mark -
#pragma mark SKProductsRequestDelegate
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *products = response.products;
if (products.count != 0)
{
_product = products[0];
_buyButton.enabled = YES;
_productTitle.text = _product.localizedTitle;
_productDescription.text = _product.localizedDescription;
} else {
_productTitle.text = #"Product not found";
}
products = response.invalidProductIdentifiers;
for (SKProduct *product in products)
{
NSLog(#"Product not found: %#", product);
}
}
////
- (IBAction)buyProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
////
#pragma mark -
#pragma mark SKPaymentTransactionObserver
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
[self unlockFeature];
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(#"Transaction state -> Restored");
//add the same code as you did from SKPaymentTransactionStatePurchased here
[self unlockFeature];
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(#"Transaction Failed");
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
default:
break;
}
}
}
////
-(void)unlockFeature
{
_buyButton.enabled = NO;
[_buyButton setTitle:#"Purchased"
forState:UIControlStateDisabled];
[_homeViewController enableLevel2];
}
- (IBAction) restore{
//this is called when the user restores purchases, you should hook this up to a button
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(#"received restored transactions: %lul", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
if(SKPaymentTransactionStateRestored){
NSLog(#"Transaction state -> Restored");
//called when the user successfully restores a purchase
[self unlockFeature];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
//// <--
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
_buyButton.enabled = NO;
}
How do i make it work for more than one IAP purchase? The ray wenderlick tutorial shows in a table view, but i don't want a table view, i want custom buttons with a custom background of my own, so this tutorial is great, but i don't know how to make it work with more than one iap. thank you in advance if u know the answer, please comment. i've been struggling over 2 days already.
In .h file add this method.
+ (RageIAPHelper *)sharedInstance;
in implementaion file .m
+ (RageIAPHelper *)sharedInstance {
static dispatch_once_t once;
static RageIAPHelper * sharedInstance;
dispatch_once(&once, ^{
NSSet * productIdentifiers = [NSSet setWithObjects:
#"com.razeware.inapprage.drummerrage",
#"com.razeware.inapprage.itunesconnectrage",
#"com.razeware.inapprage.nightlyrage",
#"com.razeware.inapprage.studylikeaboss",
#"com.razeware.inapprage.updogsadness",
nil];
sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
});
return sharedInstance;
}
by this we can get more productIdentifiers.
follow this tutorial Click Here
Hope this will help you.
I try to calculate the size of a UIWebView with a given content, but without showing the view. I only need to know the size.
My Problem: When I execute the code, the delegate of the UIWebView isn't called. Why?
MessageSizeCaluclator.h
#import < Foundation/Foundation.h>
#class Message;
#interface MessageSizeCaluclator : NSObject <UIWebViewDelegate>
- (id)initWithMessage:(Message*)message;
- (void)saveSize;
#end
MessageSizeCaluclator.m
#import "Message.h"
#import "MessageSizeCaluclator.h"
#interface MessageSizeCaluclator () <UIWebViewDelegate>
#property (strong, nonatomic) Message* message;
#property (strong, nonatomic) UIWebView* webView;
#end
#implementation MessageSizeCaluclator
#synthesize message = _message;
#synthesize webView = _webView;
- (id)initWithMessage:(Message*)message
{
self = [super init];
if (self) {
_message = message;
// WebView
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_webView.delegate = self;
}
return self;
}
- (void)saveSize
{
NSLog(#"%s message = %#", __PRETTY_FUNCTION__, _message.text);
[_webView loadHTMLString:[NSString stringWithFormat:#"<div style='font-family:Helvetica;font-size:13px;'>This is a test</div>", _message.text]
baseURL:nil];
}
#pragma mark - Web view delegate
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#end
Implementation
MessageSizeCaluclator* messageSizeCalculator = [[MessageSizeCaluclator alloc] initWithMessage:message];
[messageSizeCalculator saveSize];
Add your UIWebView to some UIView, make its frame offscreen (so users can't see it). The delegate methods won't be called if UIWebView is not in the view hierarchy of the app.
I have downloaded this project from https://github.com/yahoo/yos-social-objc .
I have changed the ConsumerKey,
ConsumerSecret
and ApplicationId but When I Run the app it crashes. It gives an error of BAD-Excess.
Does anyone has any idea of this??
please advise
Thanks
Basically its just downloaded project from yahoo's developer's page still.
This is my Complete code
SocialSampleAppDelegate.h file
#import <UIKit/UIKit.h>
#import "YOSSession.h"
#class SocialSampleViewController;
#interface SocialSampleAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
SocialSampleViewController *viewController;
YOSSession *session;
NSMutableDictionary *oauthResponse;
BOOL launchDefault;
}
#property BOOL launchDefault;
#property (nonatomic, readwrite, retain) YOSSession *session;
#property (nonatomic, readwrite, retain) NSMutableDictionary *oauthResponse;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet SocialSampleViewController *viewController;
- (void)getUserProfile;
- (void)createYahooSession;
- (void)handlePostLaunch;
#end
SocialSampleAppDelegate.m
#import "SocialSampleAppDelegate.h"
#import "SocialSampleViewController.h"
#import "YOSUser.h"
#import "YOSUserRequest.h"
#import "NSString+SBJSON.h"
#implementation SocialSampleAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize session;
#synthesize launchDefault;
#synthesize oauthResponse;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
launchDefault = YES;
[self performSelector:#selector(handlePostLaunch) withObject:nil afterDelay:0.0];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
launchDefault = NO;
if (!url) {
return NO;
}
NSArray *pairs = [[url query] componentsSeparatedByString:#"&"];
NSMutableDictionary *response = [NSMutableDictionary dictionary];
for (NSString *item in pairs) {
NSArray *fields = [item componentsSeparatedByString:#"="];
NSString *name = [fields objectAtIndex:0];
NSString *value = [[fields objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[response setObject:value forKey:name];
}
self.oauthResponse = response;
[self createYahooSession];
return YES;
}
- (void)handlePostLaunch
{
if(self.launchDefault) {
[self createYahooSession];
}
}
- (void)createYahooSession
{
// create session with consumer key, secret and application id
// set up a new app here: https://developer.yahoo.com/dashboard/createKey.html
// because the default values here won't work
self.session = [YOSSession sessionWithConsumerKey:#"MYConsumer KEy"
andConsumerSecret:#"MY Secret"
andApplicationId:#"My APPID"];
if(self.oauthResponse) {
NSString *verifier = [self.oauthResponse valueForKey:#"oauth_verifier"];
[self.session setVerifier:verifier];
}
BOOL hasSession = [self.session resumeSession];
if(!hasSession) {
[self.session sendUserToAuthorizationWithCallbackUrl:nil];
} else {
[self getUserProfile];
}
}
- (void)getUserProfile
{
// initialize the profile request with our user.
YOSUserRequest *userRequest = [YOSUserRequest requestWithSession:self.session];
// get the users profile
[userRequest fetchProfileWithDelegate:self];
}
- (void)requestDidFinishLoading:(YOSResponseData *)data
{
NSDictionary *userProfile = [[data.responseText JSONValue] objectForKey:#"profile"];
// NSLog(#"%#",[userProfile description]);
if(userProfile) {
[viewController setUserProfile:userProfile];
}
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
SocialSampleViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
[nicknameLabel setText:#"loading..."];
}
- (void)setUserProfile:(NSDictionary *)data
{
NSString *welcomeText = [NSString stringWithFormat:#"Hey %# %#!",
[[data objectForKey:#"profile"] objectForKey:#"givenName"],
[[data objectForKey:#"profile"] objectForKey:#"familyName"]];
[nicknameLabel setText:welcomeText];
}
info plist