我一直在编码整个2天的Objective-C。 我有这样的问题:Objective-C程序接收到的信号:“EXC_BAD_ACCESS”推送通知
//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;
}
你可能认识从苹果开发中心这个例子。 问题是当我试图在sendProviderDeviceToken方法中引用deviceToken时,我得到了EXC_BAD_ACCESS信号。
我在做什么错?
如果我的回答对您的评论有帮助,请将其标记为已接受,以便其他用户认为它有用。 –
我的回答有帮助吗? –