0
앱을 종료 한 후 푸시 알림을 전송하는 앱을 만들고 있습니다. 내 서버와 통신하기 위해 AFNetworking을 사용하고 있습니다. 여기 AFNetworking 기능이 있습니다.POST 요청이 서버를 통해 성공적으로 전송되지 않았습니다.
-(void)sendPushNotification:(NSMutableDictionary *)params onCompletion:(JSONResponseBlock)completionBlock{
NSLog(@"%@%@",kAPIHost,kAPIPush);
NSMutableURLRequest *apiRequest = [self multipartFormRequestWithMethod:@"POST" path:kAPIPush parameters:params constructingBodyWithBlock:^(id <AFMultipartFormData>formData){
//TODO: attach file if needed
}];
NSLog(@"Till here");
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
//success !
NSLog(@"SUCCESSSS!");
completionBlock(responseObject);
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
//Failure
NSLog(@"FAILUREE!");
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];
NSLog(@"tille here 2");
[operation start];
NSLog(@"till here 3");
}
다음 푸시 알림을 보내려면 다음 코드가 필요합니다. 우선
- (IBAction)changeEnglish:(id)sender {
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSString *alertCancel = NSLocalizedString(@"Home_alertCancel", nil);
NSString *message = @" Do you wish to change the language? The application will shut down after this. Next up you can restart it again.";
BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Change language" message:message];
[alert setCancelButtonWithTitle:alertCancel block:nil];
[alert setDestructiveButtonWithTitle:@"Ok" block:^{
[self sendPush];
exit(0);
}];
}
-(void)sendPush{
[[API sharedInstance]sendPushNotification:NULL onCompletion:^(NSDictionary *json){
//completion
if(![json objectForKey:@"error"]){
NSLog(@"notification send");
}else {
NSLog(@"Cannot connect to the server");
}
}];
}
, 내 브라우저에서 pushnotification을 실행할 때 (히트 입력 도중에 브라우저에서 링크를 입력) 그것을 잘 작동합니다. 하지만 코드에서 실행하고 싶을 때. 다음 로그를 제공합니다.
2012-12-12 13:44:43.695 doktersApp[666:907] http://linkexample/simplepush.php
2012-12-12 13:44:43.702 doktersApp[666:907] till here
2012-12-12 13:44:43.705 doktersApp[666:907] till here2
2012-12-12 13:44:43.706 doktersApp[666:907] till here3
그리고 내가 그것을 어떻게 해결할 수 있습니다 (이 확실히 검증되지 않은, 위의 테스트)? – Steaphann
죄송합니다. 여기에 방해가되었습니다. :) 아플 편집 지금 내 답변을 –
고맙습니다. – Steaphann