RJobObject * jobObj = [RJobObject new];
RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:jobDictionary destinationObject:jobObj mapping:[RJobObject mapping]];
mappingOperation.dataSource = (id)jobObj;
[mappingOperation start];
jobDictionary structure:
NSDictionary *msg1 = #{
#"id" : #"dfcd",
#"message" : #"ndjfcdfcd"
};
NSDictionary *msg2 = #{
#"id" : #"fjvdfv",
#"message" : #"kjndcdovc"
};
NSDictionary *msg3 = #{
#"id" : #"fce",
#"message" : #"dfcdf"
};
NSArray *msgsArray = [NSArray arrayWithObjects:msg1, msg2,msg3, nil];
NSMutableDictionary * jobDictionary = [NSMutableDictionary dictionaryWithDictionary:#{#"id" : #"Sourabh pant",
#"title": #"http://www.google.com"
}];
[jobDictionary setObject:msgsArray forKey:#"messages"];
/......................................................./
RJobObject is the custom object:
#property (nonatomic) NSString * id;
#property (nonatomic) long long duration;
#property (nonatomic) NSString * title;
#property (nonatomic) NSString * image;
#property (nonatomic) NSString * secret;
#property (nonatomic) NSInteger unreadCount;
#property (nonatomic) NSArray * messages;
This creates a crash inside RRestkit, if the jobDictionary contains messages.If the messages array inside jobDictionary is empty,then the code runs fine.
So to sum up the message array is not being mapped.
Stack trace
2015-11-28 15:59:22.808 Checking Rest Kit[35951:3402596] -
[RJobObject mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]: unrecognized selector sent to instance 0x79f96270
2015-11-28 16:00:48.987 Checking Rest Kit[35951:3402596] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RJobObject mappingOperation:targetObjectForRepresentation:withMapping:inRelationship:]: unrecognized selector sent to instance 0x79f96270'
*** First throw call stack:
(
0 CoreFoundation 0x018e3a14 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x013a2e02 objc_exception_throw + 50
2 CoreFoundation 0x018ecd63 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0182a6bd ___forwarding___ + 1037
4 CoreFoundation 0x0182a28e _CF_forwarding_prep_0 + 14
5 Checking Rest Kit 0x00142f48 -[RKMappingOperation destinationObjectForMappingRepresentation:parentRepresentation:withMapping:inRelationship:] + 1704
6 Checking Rest Kit 0x00149885 __64-[RKMappingOperation mapOneToManyRelationshipWithValue:mapping:]_block_invoke + 149
7 CoreFoundation 0x018152e9 __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 73
8 CoreFoundation 0x01815182 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 162
9 CoreFoundation 0x017ff835 -[NSArray enumerateObjectsUsingBlock:] + 53
10 Checking Rest Kit 0x0014920b -[RKMappingOperation mapOneToManyRelationshipWithValue:mapping:] + 2763
11 Checking Rest Kit 0x0014b4fb -[RKMappingOperation applyRelationshipMappings] + 6283
12 Checking Rest Kit 0x0014d7db -[RKMappingOperation main] + 4075
13 Checking Rest Kit 0x0014c7dd -[RKMappingOperation start] + 45
14 Checking Rest Kit 0x000ab866 -[ViewController jobObjectFromJobDictionary:] + 310
15 Checking Rest Kit 0x000ab6d5 -[ViewController fetchJobFromDbForId:] + 85
16 Checking Rest Kit 0x000ab566 -[ViewController viewDidLoad] + 918
17 UIKit 0x01e3b2ae -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
18 UIKit 0x01e3fdce -[UIViewController loadViewIfRequired] + 1384
19 UIKit 0x01e401ed -[UIViewController view] + 35
20 UIKit 0x01cedf94 -[UIWindow addRootViewControllerViewIfPossible] + 69
21 UIKit 0x01cee6b1 -[UIWindow _setHidden:forced:] + 304
22 UIKit 0x01ceea67 -[UIWindow _orderFrontWithoutMakingKey] + 49
23 UIKit 0x01d02118 -[UIWindow makeKeyAndVisible] + 80
24 UIKit 0x01c6a6e7 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4190
25 UIKit 0x01c71cd6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1989
26 UIKit 0x01c96ee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
27 UIKit 0x01c6e966 -[UIApplication workspaceDidEndTransaction:] + 163
28 FrontBoardServices 0x04c4dc76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
29 FrontBoardServices 0x04c4d74d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
30 FrontBoardServices 0x04c6b173 -[FBSSerialQueue _performNext] + 184
31 FrontBoardServices 0x04c6b5aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
32 FrontBoardServices 0x04c6a8a6 FBSSerialQueueRunLoopSourceHandler + 33
33 CoreFoundation 0x017fd6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
34 CoreFoundation 0x017f338b __CFRunLoopDoSources0 + 523
35 CoreFoundation 0x017f27a8 __CFRunLoopRun + 1032
36 CoreFoundation 0x017f20e6 CFRunLoopRunSpecific + 470
37 CoreFoundation 0x017f1efb CFRunLoopRunInMode + 123
38 UIKit 0x01c6e206 -[UIApplication _run] + 540
39 UIKit 0x01c73bfa UIApplicationMain + 160
40 Checking Rest Kit 0x000af02a main + 138
41 libdyld.dylib 0x03911a21 start + 1
42 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In Rconnection.m
- (id)destinationObjectForMappingRepresentation:(id)representation parentRepresentation:(id)parentRepresentation withMapping:(RKMapping *)mapping inRelationship:(RKRelationshipMapping *)relationshipMapping {
/* Some Code */
............
if (destinationObject == nil)
{
NSDictionary *dictionaryRepresentation = [representation isKindOfClass:[NSDictionary class]] ? representation : #{ [NSNull null] : representation };
RKMappingMetadata *parentMetadata = [RKMappingMetadata new];
parentMetadata.parentObject = self.destinationObject ?: [NSNull null];
NSArray *metadata = RKInsertInMetadataList(self.metadataList, parentMetadata, nil);
RKMappingSourceObject *sourceObject = [[RKMappingSourceObject alloc] initWithObject:dictionaryRepresentation parentObject:parentRepresentation rootObject:self.rootSourceObject metadata:metadata];
// Crashing Breakpoint below:
destinationObject = [dataSource mappingOperation:self targetObjectForRepresentation:(NSDictionary *)sourceObject withMapping:concreteMapping inRelationship:relationshipMapping];
}
.......
/* Some code */
}
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
#interface RJobObject : NSObject
#property (nonatomic) NSString * id;
#property (nonatomic) long long duration;
#property (nonatomic) NSString * title;
#property (nonatomic) NSString * image;
#property (nonatomic) NSString * secret;
#property (nonatomic) NSInteger unreadCount;
#property (nonatomic) NSArray * messages;
+(RKObjectMapping *)mapping;
#end
This line is incorrect:
mappingOperation.dataSource = (id)jobObj;
because you are giving the operation a plain data model object as a data source (and telling the compiler to like it by casting to id).
When the operation runs it needs some new instances to be created so it can map the content from the JSON dict into them, this is a job the data source is supposed to do. When the operation asks the data source you get a crash because the object you provided as the data source, jobObj, doesn't understand the request.
You need to create and set an appropriate data source that can handle this requirement.
Related
I'am a super a super rookie in IOS. I am doing a login feature. When the login in button is pressed, the APP shall check the text from storage. Then it should change to the second VC if check status return true. I currently have a ViewController to ViewController segue with identifier. I tried the perform segue with identifier but it doesn't work.(Doesn't change scene and shows no alert.)
Here is the login Page.
#import
#interface LoginPage : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *usernameField;
#property (strong, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)LoginTapped:(id)sender;
- (IBAction)SignupTapped:(id)sender;
#end
the login.m
#import "LoginPage.h"
#import "Home.h"
#implementation LoginPage
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)LoginTapped:(id)sender {
NSMutableDictionary *infodictionary =[[NSMutableDictionary alloc] init];
[infodictionary setObject:#"1" forKey:#"rose"];
[infodictionary setObject:#"2" forKey:#"cathy"];
[infodictionary setObject:#"3" forKey:#"corey"];
if ([_passwordField.text isEqualToString:[infodictionary objectForKey: _usernameField.text]]){
// Home *home = [[Home alloc] init];
[self performSegueWithIdentifier:#"ToHome" sender:self];
}
}
- (IBAction)SignupTapped:(id)sender {
NSString *_NAME = [NSString alloc];
NSString *_PASS = [NSString alloc];
_NAME= _usernameField.text;
_PASS = _passwordField.text;
}
#end
the stimulator gives me terminating with uncaught exception of type NSException
2016-02-07 05:39:49.437 project_feature_login[8249:941926] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7fb5f9c98300> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key passwordField.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102b18f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102592deb objc_exception_throw + 48
2 CoreFoundation 0x0000000102b18b89 -[NSException raise] + 9
3 Foundation 0x000000010215fa6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x000000010305004c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010327da71 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000102a59a80 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010327c454 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000103056c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000103057542 -[UIViewController loadView] + 178
10 UIKit 0x00000001030578a0 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000103058013 -[UIViewController view] + 27
12 UIKit 0x0000000102f3151c -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000102f31c05 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000102f434a5 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000102ebd396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000102ec39c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750
17 UIKit 0x0000000102ec0ba3 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000105870784 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000105870af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x0000000102a45011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x0000000102a3af3c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x0000000102a3a3f3 __CFRunLoopRun + 867
23 CoreFoundation 0x0000000102a39e08 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000102ec04f5 -[UIApplication _run] + 402
25 UIKit 0x0000000102ec530d UIApplicationMain + 171
26 project_feature_login 0x0000000102094a6f main + 111
27 libdyld.dylib 0x000000010523c92d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
Seeking for Help!!!!
Try using self.passwordField.text instead of _passwordField.text while verifying your if condition. Also check the IBOutlet connection of passwordField in Interface Builder. Class set for that UIViewController in interface must be LoginPage
I am trying to find a way to encapsulate the data for a plot and the delegate functions in one class. This will make it much simpler to create multiple plots dynamically based on the number of data sets that I acquire.
To do so, I created a class that includes the x, y data points and CPTScatterPlot object, as well as the standard delegate functions, which are now class methods that access the internal data.
When the object is instantiated, the idea is to pass it the data and the graph object, and the constructor makes "self" the data source.
Here is the code:
// DataScatterPlot.h
#import <Foundation/Foundation.h>
#import "CorePlot-CocoaTouch.h"
#interface DataScatterPlot : NSObject <CPTScatterPlotDataSource>
#property (nonatomic, strong) CPTScatterPlot *CPTScatterPlotObj;
#property (nonatomic, strong) NSMutableArray *x;
#property (nonatomic, strong) NSMutableArray *y;
- (id) initWithGraph: (CPTXYGraph*) graph DataX: (NSMutableArray*) x andDataY: (NSMutableArray*) y;
#end
// DataScatterPlot.m
#import "DataScatterPlot.h"
#implementation DataScatterPlot
-(id) initWithGraph: (CPTXYGraph *)graph DataX:(NSMutableArray *)dataX andDataY:(NSMutableArray *)dataY {
self = [super init];
if ( self != nil ) {
self.CPTScatterPlotObj = [[CPTScatterPlot alloc] init];
self.x = dataX;
self.y = dataY;
self.CPTScatterPlotObj.dataSource = (id<CPTScatterPlotDataSource>) self;
[graph addPlot:self.CPTScatterPlotObj];
}
return self;
}
// Delegate method that returns the number of points on the plot
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
NSLog(#"The count is %lu", (unsigned long)[self.x count]);
return [self.x count];
}
// Delegate method that returns a single X or Y value for a given plot.
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
// For Sigmoid
NSNumber *dataX = [self.x objectAtIndex:index];
NSNumber *dataY = [self.y objectAtIndex:index];
// FieldEnum determines if we return an X or Y value.
switch (fieldEnum) {
case CPTScatterPlotFieldX:
{
return dataX;
}
case CPTScatterPlotFieldY: // Y-Axis
{
return dataY;
}
default:
return [NSNumber numberWithFloat:0];
}
}
#end
When I run the code, I get an "unrecognized selector sent to instance" error, which seems it indicate it is looking for a method that does not exist within the object.
Is there something that I'm doing incorrectly?
Here is the error message:
2015-10-09 12:02:09.743 SigmoidWithCustomDataClass[1192:10285] -[__NSDictionaryI numberOfRecordsForPlot:]: unrecognized selector sent to instance 0x7f9a2bda7fb0
2015-10-09 12:02:10.550 SigmoidWithCustomDataClass[1192:10285] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI numberOfRecordsForPlot:]: unrecognized selector sent to instance 0x7f9a2bda7fb0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f697c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f330bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010f69f0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f5f513c ___forwarding___ + 988
4 CoreFoundation 0x000000010f5f4cd8 _CF_forwarding_prep_0 + 120
5 SigmoidWithCustomDataClass 0x000000010eaae44b -[CPTPlot reloadData] + 94
6 SigmoidWithCustomDataClass 0x000000010eaae289 -[CPTPlot drawInContext:] + 36
7 QuartzCore 0x000000010ec1b92b CABackingStoreUpdate_ + 2793
8 QuartzCore 0x000000010ed21933 ___ZN2CA5Layer8display_Ev_block_invoke + 59
9 QuartzCore 0x000000010ed217be _ZN2CA5Layer8display_Ev + 1478
10 QuartzCore 0x000000010ed164d9 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 301
11 QuartzCore 0x000000010ed16561 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
12 QuartzCore 0x000000010ec8286e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
13 QuartzCore 0x000000010ec83a22 _ZN2CA11Transaction6commitEv + 462
14 UIKit 0x000000010fcd09ed -[UIApplication _reportMainSceneUpdateFinished:] + 44
15 UIKit 0x000000010fcd16b1 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2648
16 UIKit 0x000000010fcd0095 -[UIApplication workspaceDidEndTransaction:] + 179
17 FrontBoardServices 0x0000000114bb75e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
18 CoreFoundation 0x000000010f5cb41c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
19 CoreFoundation 0x000000010f5c1165 __CFRunLoopDoBlocks + 341
20 CoreFoundation 0x000000010f5c0f25 __CFRunLoopRun + 2389
21 CoreFoundation 0x000000010f5c0366 CFRunLoopRunSpecific + 470
22 UIKit 0x000000010fccfb02 -[UIApplication _run] + 413
23 UIKit 0x000000010fcd28c0 UIApplicationMain + 1282
24 SigmoidWithCustomDataClass 0x000000010eaad71f main + 111
25 libdyld.dylib 0x0000000112474145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The plot's datasource is a dictionary. Check the rest of your code and make sure you're not reassigning the datasource anywhere.
I am trying to remove every instance of an RLMObject subclass and whenever I call [Realm defaultRealm] my app crashes. Here is what I keep getting in the console. I am using cocoapods, version 0.93.2
*** Terminating app due to uncaught exception 'RLMException', reason: 'Can't persist property 'Id' with incompatible type. Add to ignoredPropertyNames: method to ignore.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106b15c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001067aebb7 objc_exception_throw + 45
2 business_sect 0x000000010206251b -[RLMProperty initWithName:indexed:property:] + 571
3 business_sect 0x00000001020511c1 +[RLMObjectSchema propertiesForClass:isSwift:] + 1457
4 business_sect 0x000000010204fa5c +[RLMObjectSchema schemaForObjectClass:] + 812
5 business_sect 0x00000001020c4d06 +[RLMSchema initialize] + 1862
6 libobjc.A.dylib 0x00000001067af4d6 _class_initialize + 648
7 libobjc.A.dylib 0x00000001067b86e1 lookUpImpOrForward + 351
8 libobjc.A.dylib 0x00000001067c50d3 objc_msgSend + 211
9 business_sect 0x00000001020aa34d +[RLMRealm realmWithPath:key:readOnly:inMemory:dynamic:schema:error:] + 4765
10 business_sect 0x00000001020a8d78 +[RLMRealm realmWithPath:readOnly:error:] + 152
11 business_sect 0x00000001020a8bdf +[RLMRealm defaultRealm] + 111
12 business_sect 0x0000000101f386ff __40-[CGCUserManager signInUser:completion:]_block_invoke + 879
13 business_sect 0x0000000101fd39d8 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke46 + 40
14 libdispatch.dylib 0x0000000107095186 _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x00000001070b4614 _dispatch_client_callout + 8
16 libdispatch.dylib 0x000000010709ca1c _dispatch_main_queue_callback_4CF + 1664
17 CoreFoundation 0x0000000106a7d1f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x0000000106a3edcb __CFRunLoopRun + 2043
19 CoreFoundation 0x0000000106a3e366 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000107d63a3e GSEventRunModal + 161
21 UIKit 0x0000000104e6d8c0 UIApplicationMain + 1282
22 business_sect 0x0000000101f6927f main + 111
23 libdyld.dylib 0x00000001070e8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
EDIT: I am also testing on the iphone6 simulator
Here is the RLMObject subclass:
#import "RLMObject.h"
#interface CGCUser : RLMObject
#property NSString *EmailAddress;
#property BOOL IsActive;
#end
And a second object
#interface CGCCardInfo : RLMObject
#property NSInteger *Id;
#property NSString *nickName;
#property NSString *token;
#property NSString *displayNumber;
#property BOOL *isDefault;
#property NSString *cardType;
#end
RLM_ARRAY_TYPE(CGCCardInfo)
The issue there is the line #property BOOL *isDefault;
If you change that to #property BOOL isDefault; it should do exactly what you want!
The same happened to me.
#property NSInteger *Id is the problematic field over here. You use a pointer to NSInteger instead of NSInteger itself.
The solution is to replace it with a direct reference: #property NSInteger Id
I am trying to make my first Objective-C library. I am creating a method which will take in a UIImage and return NSMutableData. I have created the following:
+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image
{
int maxWidth = 100;
BOOL drawerKick = YES;
BOOL compressionEnable = YES;
RasterDocument *rasterDoc = [[RasterDocument alloc] initWithDefaults:RasSpeed_Medium endOfPageBehaviour:RasPageEndMode_FeedAndFullCut endOfDocumentBahaviour:RasPageEndMode_FeedAndFullCut topMargin:RasTopMargin_Standard pageLength:0 leftMargin:0 rightMargin:0];
StarBitmap *starbitmap = [[StarBitmap alloc] initWithUIImage:image :maxWidth :false];
NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
NSData *shortcommand = [rasterDoc BeginDocumentCommandData];
[commandsToPrint appendData:shortcommand];
shortcommand = [starbitmap getImageDataForPrinting:compressionEnable];
[commandsToPrint appendData:shortcommand];
shortcommand = [rasterDoc EndDocumentCommandData];
[commandsToPrint appendData:shortcommand];
if (drawerKick == YES) {
[commandsToPrint appendBytes:"\x07"
length:sizeof("\x07") - 1]; // KickCashDrawer
}
[starbitmap release];
[rasterDoc release];
return commandsToPrint;
}
Just for testing purposes, I am trying to call it from a button click event:
- (IBAction)DevButton_TouchUpInside:(id)sender {
UIImage *imageToPrint = [UIImage imageNamed:#"image1.png"];
// NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
// *commandsToPrint=[self GetDataToSendToPrinter:imageToPrint];
//This is where I call it
NSMutableData *commandsToPrint = [self GetDataToSendToPrinter:imageToPrint];
int commandSize = (int)[commandsToPrint length];
unsigned char *dataToSentToPrinter = (unsigned char *)malloc(commandSize);
[commandsToPrint getBytes:dataToSentToPrinter];
NSString *portName = #"TCP:10.0.1.4";
NSString *portSettings = #"Standard";
NSMutableString *message;
SMPort *starPort = nil;
starPort = [SMPort getPort:portName :portSettings :10000];
[starPort writePort:dataToSentToPrinter :0 :commandSize];
}
However I keep getting the following crash when clicking on the button:
Warning: Error creating LLDB target at path '/Users/.../Library/Developer/Xcode/DerivedData/IOS_SDK-cjctcqoxudpegpadjbwitveqtkso/Build/Products/Debug-iphonesimulator/StarIO SDK.app'- using an empty LLDB target which can cause slow memory reads from remote devices.
2014-09-26 18:39:22.588 StarIO SDK[17823:513276] -[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260
2014-09-26 18:39:22.624 StarIO SDK[17823:513276] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260'
*** First throw call stack:
(
0 CoreFoundation 0x021c4df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01c49a97 objc_exception_throw + 44
2 CoreFoundation 0x021cca75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x021159c7 ___forwarding___ + 1047
4 CoreFoundation 0x0211558e _CF_forwarding_prep_0 + 14
5 StarIO SDK 0x000428bb -[IOS_SDKViewControllerRasterMode DevButton_TouchUpInside:] + 107
6 libobjc.A.dylib 0x01c5f7cd -[NSObject performSelector:withObject:withObject:] + 84
7 UIKit 0x0042179d -[UIApplication sendAction:to:from:forEvent:] + 99
8 UIKit 0x0042172f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
9 UIKit 0x00554a16 -[UIControl sendAction:to:forEvent:] + 69
10 UIKit 0x00554e33 -[UIControl _sendActionsForEvents:withEvent:] + 598
11 UIKit 0x0055409d -[UIControl touchesEnded:withEvent:] + 660
12 UIKit 0x00471aba -[UIWindow _sendTouchesForEvent:] + 874
13 UIKit 0x00472595 -[UIWindow sendEvent:] + 791
14 UIKit 0x00437aa9 -[UIApplication sendEvent:] + 242
15 UIKit 0x004478de _UIApplicationHandleEventFromQueueEvent + 20690
16 UIKit 0x0041c079 _UIApplicationHandleEventQueue + 2206
17 CoreFoundation 0x020e87bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x020de2cd __CFRunLoopDoSources0 + 253
19 CoreFoundation 0x020dd828 __CFRunLoopRun + 952
20 CoreFoundation 0x020dd1ab CFRunLoopRunSpecific + 443
21 CoreFoundation 0x020dcfdb CFRunLoopRunInMode + 123
22 GraphicsServices 0x03b8c24f GSEventRunModal + 192
23 GraphicsServices 0x03b8c08c GSEventRun + 104
24 UIKit 0x0041fe16 UIApplicationMain + 1526
25 StarIO SDK 0x000027e2 main + 130
26 libdyld.dylib 0x036f0ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I asume I am missing something really basic. It's the first Objective-C method I have created, I'm just looking at building a simple library I can then wrap in a Xamarin binding. Where am I going wrong?
You're calling a class method from an instance method.
+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image //Should be called using the class name
- (IBAction)DevButton_TouchUpInside:(id)sender //Should be called using self
I'm not sure how that compiled actually, you should've gotten an error like this:
No visible #interface for IOS_SDKViewControllerRasterMode declares the selector 'GetDataToSendToPrinter:'
Per the log it spit out, it's not finding the function GetDataToSendToPrinter:. Try calling it as a class method:
NSMutableData *commandsToPrint = [IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:imageToPrint];
I called method in another class (they are both singletons).
WebserviceHelper.h
#interface WebserviceHelper : NSObject {
int currentType;
NSString *SERVER_URL;
WebserviceManager *webService;
}
#property (nonatomic, assign) id delegate;
- (void)retrieveStudentwithCode:(NSString *)code {
currentType = STUDENT_TYPE;
NSString *param = [NSString stringWithFormat:#"token=uencom&cid=%#", code];
NSString *link = [NSString stringWithFormat:#"%#getStudentInfo", SERVER_URL];
[webService retrieveData:link withParameters:param];
}
After call webservice and get data it cached here in received data. I check and it works fine
but when it deliver to didFinishLoading error happen here
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)receivedData {
data = [NSMutableData new];
[data appendData:receivedData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[delegate: data];
}
Call stack:
2014-08-20 10:39:05.187 School-Link[1030:60b] -[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420
2014-08-20 10:39:05.188 School-Link[1030:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420'
*** First throw call stack:
(
0 CoreFoundation 0x01bf31e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018f08e5 objc_exception_throw + 44
2 CoreFoundation 0x01c90243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01be350b ___forwarding___ + 1019
4 CoreFoundation 0x01be30ee _CF_forwarding_prep_0 + 14
5 School-Link 0x00030c82 -[WebserviceManager connectionDidFinishLoading:] + 242
6 Foundation 0x016b9e49 ___NSURLConnectionDidFinishLoading_block_invoke + 40
7 Foundation 0x016507e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
8 Foundation 0x014d8f5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
9 Foundation 0x014d8ec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
10 Foundation 0x014d8dd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
11 Foundation 0x014d9188 _NSURLConnectionDidFinishLoading + 43
12 CFNetwork 0x02a3169f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
13 CFNetwork 0x02a2f3de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
14 CoreFoundation 0x01b94c69 CFArrayApplyFunction + 57
15 CFNetwork 0x02998441 _ZN19RunloopBlockContext7performEv + 155
16 CFNetwork 0x02a7a3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
17 CFNetwork 0x02998257 _ZN17MultiplexerSource7performEv + 299
18 CFNetwork 0x0299806c _ZN17MultiplexerSource8_performEPv + 76
19 CoreFoundation 0x01b7c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20 CoreFoundation 0x01b7c1d5 __CFRunLoopDoSources0 + 437
21 CoreFoundation 0x01b991ae __CFRunLoopRun + 910
22 CoreFoundation 0x01b989d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x01b987eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x0338d5ee GSEventRunModal + 192
25 GraphicsServices 0x0338d42b GSEventRun + 104
26 UIKit 0x005b0f9b UIApplicationMain + 1225
27 School-Link 0x00018f6d main + 141
28 libdyld.dylib 0x03026701 start + 1
29 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Try this, have a protocol declaration in WebserviceHelper.h like
#protocol studentDataDelegate <NSObject>
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
#end
WebserviceHelper.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
[self.delegate WebserviceHelper:self didStudentDataDownloadCompleteWithData:data];
}
so which ever class confirms to the above protocol should implement the delegate method like,
#interface RequestingDataClass : UIViewController <studentDataDelegate>
by doing this you will receive the warning that you have not implemented didStudentDataDownloadCompleteWithData:method so do it like
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
{
webserviceHelper.delegate=self;
// Do something with the `data`
}
You do no show the declaration of the delegate, however this statement:
[delegate: data];
Should be:
[delegate haveSomeData:data];
(or something similar)
did you create protocol in your WebserviceHelper.h file like this?
#protocol WebserviceHelperDelegate <NSObject>
#required
-(void)reciveData:(NSData *)data;//or your method
#end
decleare a property
#property (nonatomic,strong) id <WebserviceHelperDelegate> delegate;
then call this method like
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[self.delegate reciveData: data];
}
And implement this method from where you call webservice class and assign delegate
-(void)reciveData:(NSData *)data{
}