Я кодирую Objective-C целых 2 дня.У меня есть эта проблема:
//Notification methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken started with %@", deviceToken);
const void *devTokenBytes = [deviceToken bytes];
self->registered = YES;
//NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken ended with %@", devTokenBytes);
[self sendProviderDeviceToken:devTokenBytes];
}
- (void) application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"didFailToRegisterForRemoteNotificationsWithError started with %@", error);
}
- (BOOL)sendProviderDeviceToken:(void *)deviceToken
{
//NSLog(@"sendProviderDeviceToken started with %@", deviceToken);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://some_url//pushRegistration"]];
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:deviceToken, @"registrationId", @"06d746d0-e67e-11e0-911d-c42c0322474a", @"authenticationToken", @"apns", @"type", nil];
NSError *theError = NULL;
NSData *theData = [[CJSONSerializer serializer] serializeObject:dict error:&theError];
NSData *requestData = [NSData dataWithBytes:[theData bytes] length:[theData length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSLog(@"returnData: %@", returnString);
return YES;
}
Вы, вероятно, узнаете этот пример из Apple Dev Center.Проблема в том, что я получаю сигнал EXC_BAD_ACCESS при попытке обратиться к deviceToken в методе sendProviderDeviceToken.
Что я делаю не так?