현재 Firebase가이 시나리오를 처리 할 준비가되어 있다고 생각하지 않습니다. 그것을 처리하기 위해서는 약간의 사이드 코드가 필요합니다. 어느 쪽이든 당신은 호스팅 얻을 작동, 또는 당신이 백엔드 역할을 할 수있는 또 다른 서비스를 찾을 필요가
[[FIRMessaging message]sendMessage:(nonnull NSDictionary *)message
to:(nonnull NSString *)receiver
withMessageID:(nonnull NSString *)messageID
timeToLive:(int64_t)ttl;
코드를 통합하는 데 사용 할 수있는 PHP를 엔드 포인트처럼 만들 수 있습니다.
https://techcrunch.com/2016/02/02/batch-now-integrates-with-firebase-to-create-a-parse-alternative/
이 Batch.com 회사는 내가 지금까지 찾은 최고의 솔루션이 될 것으로 보인다. 사용자 장치가 자신의 서버에있는 엔드 포인트로 json 페이로드를 보내 사용자 지정 푸시 알림을 특정 대상 장치에 보냈습니다. Batch는 특히 Push Notification 회사 인 것으로 보이며, 무료 기본 계획이 Parse가 작동하는 방식에 대해, 당신이 필요로하는 것을 처리 할만큼 충분히 좋은 것처럼 보입니다.
다음은 푸시 알림 Objective C를 보내기 위해 작성한 실제 코드입니다. Batch에서 다운로드 할 수있는 Swift 2 및 Swift 3 예제가 있습니다.com)
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.batch.com/1.1/(your API code here)/transactional/send"]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0f];
[theRequest setValue:@"(your other API key here" forHTTPHeaderField:@"X-Authorization"];
NSDictionary *messageDict = [[NSDictionary alloc]initWithObjectsAndKeys:@"Hey This is a Push!", @"title", @"But it's a friendly push. Like the kind of push friends do to each other.",@"body", nil];
NSArray *recipientsArray = [[NSArray alloc]initWithArray:someMutableArrayThatHasUsersFirebaseTokens];
NSDictionary *recipientsDict = [[NSDictionary alloc]initWithObjectsAndKeys:recipientsArray, @"custom_ids", nil];
NSDictionary *gistDict = @{@"group_id":@"just some name you make up for this pushes category that doesn't matter",@"recipients":recipientsDict,@"message":messageDict, @"sandbox":@YES};
NSError *jsonError;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:gistDict options:NSJSONWritingPrettyPrinted error:&jsonError];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:jsonData];
NSOperationQueue *queue1 = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:theRequest queue:queue1 completionHandler:^(NSURLResponse *response, NSData *POSTReply, NSError *error){
if ([POSTReply length] >0 && error == nil){
dispatch_async(dispatch_get_main_queue(), ^{
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding:NSASCIIStringEncoding];
NSLog(@"BATCH PUSH FINISHED:::%@", theReply);
});
}else {
NSLog(@"BATCH PUSH ERROR!!!:::%@", error);
}
}];
배치는 Cocoa Pods로 설치하기가 매우 쉽습니다.
애플 대리자에서 :
@import Batch
didFinishLaunching에서 :
[Batch startWithAPIKey:@"(your api key)"]; // dev
[BatchPush registerForRemoteNotifications];
을 나중에 응용 프로그램의 위임에 :
- (void)tokenRefreshNotification:(NSNotification *)notification {
// Note that this callback will be fired everytime a new token is generated, including the first
// time. So if you need to retrieve the token as soon as it is available this is where that
// should be done.
NSString *refreshedToken = [[FIRInstanceID instanceID] token];
NSLog(@"InstanceID token: %@", refreshedToken);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:refreshedToken forKey:@"pushKey"];
[defaults synchronize];
BatchUserDataEditor *editor = [BatchUser editor];
[editor setIdentifier:refreshedToken]; // Set to `nil` if you want to remove the identifier.
[editor save];
[self connectToFcm];
}
나는 또한 작업을 얻기 위해이 코드를 사용
Batch.com 웹 사이트에서 설명하는 설치 및 설치 작업 외에도 작업 방법을 설명합니다. 당신이 중포 기지에서 토큰을 일단
, 당신은 기본적으로 앱 위임에
BatchUserDataEditor *editor = [BatchUser editor];
[editor setIdentifier:refreshedToken];
[editor save];
와 배치에 등록합니다. 그런 다음 사용자 device1이 다른 device2에 Push를 보내도록하려는 경우 device1의 사용자 정의 id를 device2에 어떻게 든 보냈다고 가정하면 해당 사용자 정의 ID를 사용하여 Push notification 페이로드를 Batch.com의 API로 보내고 Batch가 서버를 처리 할 수 있습니다 Apple APN에 사이드 항목이 표시되고 푸시 알림이 device2에 나타납니다.
장치에 장치를 보내려면 흐름에 대해 정확해야합니다. 서버로 업스트림을 보내면 서버가 다운 스트림을 다른 장치로 보냅니다. –