Dropbox iOS API - Simple Questions / DBRestClient Problems - ios

EDIT:
I think I have fixed my issues. Thank you for the help - I really appreciate it.
Original Question:
I am new to objective-c and iOS programming, so hopefully my issues are not difficult to correct. I am trying to add the ability to open a file from Dropbox to my simple iOS application. I have been following the tutorial here:
http://www.mathiastauber.com/integration-of-dropbox-in-your-ios-application-making-api-calls/
I have so far successfully gotten my app to link to my Dropbox account and display the "link successful" message.
Now I am having trouble using the DBRestClient. I have the following code currently:
myviewcontroller.h
...
#end
DBRestClient *restClient;
myviewcontroller.m
- (DBRestClient *)restClient {
if (!restClient) {
restClient =
[[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate = self;
}
return restClient;
}
I am getting an error on the line
restClient.delegate = self;
that says
"Assigning to 'id<DBRestClientDelegate>' from incompatible type 'myviewcontroller'"
What could be going wrong? I have read through every example I can find and can see no issues with what I am trying to do.
If I try to cast by doing the following, it does not work
restClient.delegate = (id)self;
I have also found that if I remove the code in myviewcontroller.m and only have the variable declaration in the header file (as shown above) I get an error that says "Apple Mach-O Linker Error"
I would greatly appreciate any help you can provide. I am very much stuck with this problem.

In your header file you need to specify that you adhere to the DBRestClientDelegate's protocol.
For example:
#interface MyViewController: UIViewController <DBRestClientDelegate>
If you're already adhering to other protocols, simply add the DBRestClientDelegate and comma seperate, such as...
#interface MyViewController: UIViewController <UITableViewDelegate, DBRestClientDelegate>
For more information, I'd recommend a read of the Delegation section of Cocoa Core Competencies, especially as you'll be encountering delegates (and indeed perhaps defining your own protocols, etc.) a lot in Cocoa.

The error is because the right side of restClient.delegate = self; is not of type id<DBRestClientDelegate>
id<DBRestClientDelegate> is basically any object that conforms to the DBRestClientDelegate protocol
The first step (maybe only step) to removing the error is in your Myviewcontroller.h file
change
#interface Myviewcontroller : UIViewController //<-- my best guess at your interface line
to
#interface Myviewcontroller : UIViewController <DBRestClientDelegate>

Related

Receiver '**' for class message is a forward declaration Error. Swift Static Library use in Objective-C

I am trying to make a Swift Static library and apply it to Swift and Objective Project.
import Foundation
#objc open class Library001_Test: NSObject {
public override init(){}
#objc public func testPrint() {
print("My Name is Andi")
}
#objc public func getUUID(userName: String) -> String {
let uuid = UUID().uuidString
return "\(userName)'s UUID : \(uuid)"
}
}
I wrote the code like this using Swift.
And in the Edit Scheme menu, I changed the Build Configuration to Release and proceeded with Run. As a result, the 'libLibrary001.a' file and the 'Library001.swiftmodule' folder were created.
These two artifacts work well when pasted into a Swift project and imported.
But the problem is an Objective-C project.
I put both artifacts into my project and checked:
[General - Frameworks, Libraries. and Embedded Content] whether the library is recognized
Whether the library is recognized in [Build Phases - Link Binary With Libraries]
Check [Build Settings - Library Search Paths] address
Defines Module - Yes
And I put '#class Library001_Test;' in ViewController.h
#import <UIKit/UIKit.h>
#class Library001_Test;
#interface ViewController : UIViewController
#end
And in ViewController.m, '#import "ProductName-Swift.h" and the created Class were loaded.
#import "ViewController.h"
#import "SwiftInObjectiveC-Swift.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
Library001_Test *test = [[Library001_Test alloc] init];
}
#end
error : Receiver 'Library001_Test' for class message is a forward declaration
error : Receiver type 'Library001_Test' for instance message is a forward declaration
An error occurred while doing this. I've tried all the methods I've found on the internet and I'm wondering where the problem is.
Is the code the problem? Did I not set it up well??
The Swift file created in the project is import well in Objective-C... Why the hell is the .a file not working like this?
My problem was with '(ProductName)-Swift.h'
If you look at how Swift Code is used in Objective-C, many articles say to import (ProductName)-Swift.h. So I only added the project header that I want to apply, but I also need to add the product header made from the library.
My problem was simple, but it took me a long time to figure it out. The error was not found 'Class' and 'func' in Swift static library. My workaround was resolved using the (LibraryProductName)-Swift.h of the library I created, rather than the (ProductName)-Swift.h of the project you are working on.
If you refer to the address below, you can prevent the error that occurred in advance.
https://medium.com/#mail2ashislaha/swift-objective-c-interoperability-static-libraries-modulemap-etc-39caa77ce1fc

How to call methods in the custom view in iOS module, from titanium project?

I need to call methods in the custom view in iOS module from titanium project. I have followed the tutorials in Appcelarator documentation about creating iOS module. I could create the custom view in Titanium using below code.
var manage = require('com.test');
var manageView = manage.createView({
left:40,
right:40,
top:40,
height: 250,
backgroundColor:'blue' }); manageView.customMethodInView();
But i got error like "customMethodInView is not a function" when i run the app.
#import "TiViewProxy.h"
#import "CustomView.h"
#interface ComTestViewProxy : TiViewProxy {
CustomView *customView;
}
- (void) customMethodInView;
#end
This is the code in viewProxy class in iOS Module project.
Please help.
I know this is late, but for any wondering soul out there, it is my understanding that even if you don't intend to pass an argument for your method, the signature of the method in the native module should always take one:
your method
- (void) customMethodInView;
should look like this :
- (void)customMethodInView:(id)unused;

Method not implemented in protocol (using wit.ai SDK)

I'm using the wit.ai iOS SDK for the first time and I followed step by step what is written in the getting started page in official website https://wit.ai/docs/ios/3.1.1/quickstart. I got this error:
Method 'witDidGraspIntent:entities:body:error:' in protocol 'WitDelegate' not implemented.
I could still run the app and the message is shown in my inbox (in console) but not response is being sent back and the application crashes. I got this error:
Error when enqueuing buffer from callback
Here is my code
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
UILabel *labelView;
}
- (void)witDidGraspIntent:(NSArray *)outcomes
messageId:(NSString *)messageId
customData:(id)customData
error:(NSError*)e {
//Implementation here...
labelView.text = #"Hey what's up";
[self.view addSubview:labelView];
}
ViewController.h
#import <UIKit/UIKit.h>
#import <Wit/Wit.h>
#interface ViewController : UIViewController <WitDelegate>
#end
Thanks.
Dude, the crash message you are getting is telling you exactly what is wrong.
Method 'witDidGraspIntent:entities:body:error:' in protocol
'WitDelegate' not implemented.
You are missing a method (witDidGraspIntent:entities:body:error:) in your implementation of the protocol. You must implement all the required methods in a protocol. In this case the missing method is witDidGraspIntent:entities:body:error:.
You ask "Should I add a new -void ??" By that, if you mean should you add an implementation of the witDidGraspIntent:entities:body:error: method, the answer is YES!
I haven't used the wit.ai SDK before. You might want to edit your question and ask people who have used that SDK for help in implementing the method if you can't figure out how to do it on your own. You might also want to add "(using wit.ai SDK)" to your question title so people familiar with that framework notice your question.

Xcode Admob singleton - "use of undeclared identifier "shared"" error

Okay first post ever on any forum but i'll do my best to describe my problem. I'm a beginner at Xcode so i'm sorta expecting an easy solution, but i just can't seem to figure this one out.
In Xcode i am trying to create an Admob singleton to get admob in all my view controllers. Admob will back up iAd, which will be showed should Ad fail.
I followed this guide: http://googleadsdeveloper.blogspot.dk/2012/04/creating-gadbannerview-singleton-in.html
I created a GADMasterViewController .m and .h file
The GADMasterViewController.h looks like this
#import "GADBannerView.h"
#interface GADMasterViewController : UIViewController <GADBannerViewDelegate> {
GADBannerView *adbanner_;
BOOL isLoaded_;
id currentDelegate_;
}
#end
and the GADMasterViewController.m file looks exactly as the one in the guide except i put #import "GADMasterViewController.h" at the top.
Then in my viewController.m where i want the ad to show i put
- (void)bannerView:(GADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
_UIiAd.hidden = YES;
shared = [GADMasterViewController singleton];
[shared resetAdview:self]
}
However in viewController.m i get the following errors:
https://dl.dropboxusercontent.com/u/63928888/Sk%C3%A6rmbillede%202014-09-15%20kl.%2000.17.02.png
Basically it doesn't recognize the returned "shared" err singleton (or whatever "shared" is) from GADMasterViewController.m
How do i "get" "shared" so my viewController doesn't produce these errors?
You are using shared, but you haven't defined it as a variable (local or otherwise).
So, change
shared = [GADMasterViewController singleton];
[shared resetAdview:self]
to either
GADMasterViewController *shared = [GADMasterViewController singleton];
[shared resetAdview:self];
or
[[GADMasterViewController singleton] resetAdview:self];
so that you are defining the variable, or so that you don't need a variable.

EXC_BAD_ACCESS using ARC only during testing

I have an issue where I'm getting bad access exceptions but only when running a testing build (calling the same methods in a debug build doesn't cause the problem to come up). The project has ARC enabled and I'm running this on the iPad 5.1 simulator using Xcode 4.3:
Here's where the problem crops up:
- (void)testChangeFoodNotification {
Player* p = [[Player alloc] init];
[p addObserver:self forKeyPath:#"food" options:0 context:0]; // <-EXC_BAD_ACCESS (code=2)
p.food += 1;
STAssertTrue(_wasNotifiedOfFoodChange, nil);
}
At the point when the addObserver: method is called it doesn't seem like any of the objects involved should have been released so what could be causing the exception?
EDIT:
Apologies if it wasn't clear but the code above is being executed as part of a test case (using the standard Xcode OCUnit). Also in case it clarifies anything here's the relevant code from the player class (there's other ivars and methods but they don't have any connection to the property or methods being tested):
// Public interface
#interface Player : NSObject
#property (nonatomic, assign) NSInteger food;
#end
// Private interface
#interface Player() {
NSInteger _food;
}
#end
#implementation Player
#synthesize food = _food;
#pragma mark - Getters/Setters
- (void)setFood:(NSInteger)food {
[self willChangeValueForKey:#"food"];
_food = food;
[self didChangeValueForKey:#"food"];
}
If your class is indeed key-value compliant, ensure that the implementation for the class exhibiting the issue is not included in your test product. This means that the Target Membership panel of the Identity inspector for your .m file should only have your app checked (not YourAppTests).
I experienced the same issue in Xcode 4.3.1 when an implementation was included in both products and I registered observers in both production and test code. The following logs tipped me off:
Class YourClass is implemented in both /Users/yourUser/Library/Application Support/iPhone Simulator/5.1/Applications//YourApp.app/YourApp and /Users/yourUser/Library/Developer/Xcode/DerivedData/YourApp-/Build/Products/Debug-iphonesimulator/YourAppTests.octest/YourAppTests. One of the two will be used. Which one is undefined.
As per the Key-Value Observing Programming Guide, is your Player key-value-compliant? You want to make sure you are Ensuring KVC Compliance. I also assume that you have also implemented your observeValueForKeyPath:ofObject:change:context:? If you think you've done all of this and it's still not working, then perhaps you can share your code.
Also, minor thing, but I assume this is a code snippet to highlight the issue. I only mention it because ARC is going to be releasing your p object at the end of your testChangeFoodNotification and I would have thought that you'd want to remove your observer first.

Resources