Can't initialize RMConnectCenter of RenRen SDK - ios

I tried to make Renren iOS app along with SocialPlugin docs.
http://wiki.mobile.renren.com/en/index.php/Social_Plugin_Download
I made AppDelegate belows. But every time I invoke app, it failed
at the point of RMConnectCenter initializeConnectWithAPIKey.
The Code is like this.
--noriakiAppDelegate.h--
#import <UIKit/UIKit.h>
#import "RMConnectCenter.h"
#class noriakiViewController;
#interface noriakiAppDelegate : UIResponder <UIApplicationDelegate,RenrenMobileDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) noriakiViewController *noriakiviewcontroller;
#end
--noriakiAppDelegate.h.m--
#import "noriakiAppDelegate.h"
#import "noriakiViewController.h"
#implementation noriakiAppDelegate
#synthesize window = _window;
#synthesize noriakiviewcontroller = _noriakiviewcontroller;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[RMConnectCenter initializeConnectWithAPIKey:#"MY API KEY" secretKey:#"MY SECRET" appId:#"2080970" mobileDelegate:self];
return YES;
}

You mean application crashes when you call initializeConnectWithAPIKey ?
You are not passing your API Key and secret
[RMConnectCenter initializeConnectWithAPIKey:#"MY API KEY" secretKey:#"MY SECRET" appId:#"2080970" mobileDelegate:self];
Are you using storyboards?

Related

Accessing AppDelegate Property

I would like to pass a string to all my other view controllers from the AppDelegate. I have defined a variable called appName and assign it a string
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) NSString *appName;
#end
AppDelegate.m
#implementation AppDelegate
#synthesize appName;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
appName=#"SatKacPara";
return YES;
}
The following implementation does not have access to appName property. I could not able to figure out.
ViewController1.m
appLabel.text=[(AppDelegate*) [UIApplication shareApplication].delegate ].appName;
You have a simple typo in your line of code. It should be:
appLabel.text = ((AppDelegate*)[UIApplication sharedApplication].delegate).appName;
But using such a property isn't necessary. You can get the app's display name without hardcoding it.
Get rid of your appName property and change this line of code to:
appLabel.text = [NSBundle mainBundle].infoDictionary[#"CFBundleDisplayName"];
This has the advantage of showing the right name even if you rename your app or localize it.

Did I implement iAd shared banner wrongly?

Besides, adding the iAd and AdMob code to get banner to appear on screen, is the following code the correct way to set up a shared banner?
In AppDelegate.h
#import GoogleMobileAds;
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property(nonatomic, strong) ADBannerView *iAdView;
#property(nonatomic, strong) GADBannerView *adMobView;
#end
AppDelegate.m
#import "AppDelegate.h"
#import <iAd/iAd.h>
#implementation AppDelegate
#synthesize iAdView;
#synthesize adMobView;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
iAdView= [[ADBannerView alloc]init];
return YES;
}
iPhone6.m
#import "iPhone6.h"
#import <iAd/iAd.h>
#import "AppDelegate.h"
-(AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(void)viewDidLoad{
iAdView =[[self appdelegate] iAdView];
}

How to solve the error 'No visible #interface for 'UIViewController' declares the selector ''

I am using Xcode 5
This is my AppDelegate.h file
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UIViewController *viewController;
#end
This is my AppDelegate.m file
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.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.
[self.viewController saveData];
}
- (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.
[self.viewController loadData];
}
- (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:.
}
#end
This is my ViewController.h file
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
//some variables declared here
#interface ViewController : UIViewController <UIActionSheetDelegate, UINavigationBarDelegate, UIImagePickerControllerDelegate>{
//some outlets declared here
}
//some actions and - (void) declared here
- (NSString *) getFilePath;
- (void) saveData;
- (void) loadData;
#end
Beside the code [self.viewController saveData] and [self.viewController loadData] there's an error message:'No visible #interface for 'UIViewController' declares the selector 'saveData' and 'No visible #interface for 'UIViewController' declares the selector 'loadData'.
What should I do?
You should specify class of UIViewController in your AppDelegate.h file:
#property (strong, nonatomic) ViewController *viewController;
and add import statement in this file
#import "ViewController.h"
Your viewController is subclass of UIViewController class so there is not saveData/LoadData method.
The two method exists in your custom class - ViewController.
The solution is replace line in AppDelegate.h from:
#property (strong, nonatomic) UIViewController *viewController;
to:
#property (strong, nonatomic) ViewController *viewController;
or cast viewController to ViewController every time you call saveData/loadData
If the view controller in the app delegate is truly a ViewController object, then change the property to say so:
#property (strong, nonatomic) ViewController *viewController;
You will then also need the matching #class (.h) and #import (.m) statements.

Receiver 'SMClient' for class message is a forward declaration

I'm trying to add StackMob to my project. It says to create an SMClient instance after having dragged the SDK to the project, checking 'create groups for..' and adding to target. I followed these steps.
However, when I'm creating my SMClient and SMCoreDataStore instances, it gives me an error of Receiver 'SMClient' for class message is a forward declaration and the same for SMCoreDataStore. Here's my code:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#class SMClient;
#class SMCoreDataStore;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (strong, nonatomic) SMCoreDataStore *coreDataStore;
#property (strong, nonatomic) SMClient *client;
#end
And part of my .m:
#import "AppDelegate.h"
#import "StackMob.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.client = [[SMClient alloc] initWithAPIVersion:#"0" publicKey:#"YOUR_PUBLIC_KEY"];
self.coreDataStore = [self.client coreDataStoreWithManagedObjectModel:self.managedObjectModel];
return YES;
}
I already cleaned the project, imported the relevant header files, but it still gives that error.
Any ideas?
This might be happening because you forgot to import the classes.
Add it on your .m:
#import "SMClient.h"
#import "SMCoreDataStore.h"

ios delegate doesn't fire

i try a simple Delegate but the method won't fire. Here is my code:
The view with the protocol and a button which should trigger the delegate:
ViewController.h
#import <UIKit/UIKit.h>
#protocol InitStackDelegate <NSObject>
#required
-(void)initstack:(NSInteger)amount;
#end
#interface ViewController : UIViewController{
IBOutlet UITextField *amountTextField;
__unsafe_unretained id<InitStackDelegate> delegate;
}
- (IBAction)init:(id)sender;
#property (nonatomic,assign)id delegate;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize delegate;
- (IBAction)init:(id)sender {
//send the delegate
[delegate initstack:[amountTextField.text intValue]];
}
AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate,InitStackDelegate> {
}
#property (strong, nonatomic) UIWindow *window;
#property (strong,nonatomic) ViewController *myView;
#end
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize window;
#synthesize myView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//..... push second controller into navigation stack
myView.delegate = self;
return YES;
}
...
#pragma mark Delegate Method
-(void)initstack:(NSInteger)amount{
NSInteger test;
}
#end
When i hit the button i get to (IBAction) init but then the delegate do nothing. I set a breakpoint in AppDelegate.m but it is never reached. Any help?
thx
Mario
In you App Delegate, when you set myView.delegate=self myView doesn't actually point to anything!
You need to set myView to point to your ViewController.
Use this in didFinishLaunchingWithOptions
myView = (ViewController *)self.window.rootViewController;
myView.delegate = self;

Resources