nifty cloud mobile backend에서 Push 알림 구현
16696 단어 iOS푸시 알림Objective-CXcodemBaas
nifty cloud mobile backend란 무엇입니까?
니프티 클라우드mobile backend
정말로 마음대로
nifty cloud mobile backend 라고 매회 입력하는 것이 귀찮기 때문에 이후는 「 mBaaS 」라고 합니다.mBaaS란?
스마트폰 앱 백엔드 개발
개발 불필요한 클라우드 서비스

인용구 : htp // mb. cぉd. 에 fty. 이 m/아보 t. htm
준비
Podfile
pod 'NCMB', :git => 'https://github.com/NIFTYCloud-mbaas/ncmb_ios.git'
$ pod install
$ open PROJECT_NAME.xcworkspace
iOS 앱 측 구현
푸시 알림 수락 알림
여기 경고를 내는 것은 앱에 따라 마치 마치라고 생각합니다. 사실 어디서나 좋습니다!
채팅 앱이라면 처음으로 메시지 화면으로 이동했을 때 경고를 표시하도록 해도 됩니다.
AppDelegate.m
#import <NCMB/NCMB.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NCMB setApplicationKey:@"アプリケーションキー" clientKey:@"クライアントキー"];
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
//iOS8以上
UIUserNotificationType type = UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound;
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:type
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:setting];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
//iOS7以下
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
}
또,
mBaaS 의 리포지터리에 적당할 정도의 풀릭을 내고 있으므로 병합되면 여기가 1행으로 끝나게 됩니다.
이 설정을 잊지 마세요! ! 이미지에서 꺼져 있지만 켜십시오! !
디바이스 토큰 취득 후
AppDelegate.m
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NCMBInstallation *installation = [NCMBInstallation currentInstallation];
//Device Tokenを設定
[installation setDeviceTokenFromData:deviceToken];
//端末情報をデータストアに登録
__weak typeof (self) weakSelf = self;
[installation saveInBackgroundWithBlock:^(NSError *error) {
if(error){
//端末情報の登録が失敗した場合の処理
NSLog(@"Failed: %@", error);
if (error.code == 409001) {
//失敗した原因がdeviceTokenの重複だった場合、上書き処理を行う
[weakSelf updateExistInstallation:installation];
} else {
//deviceTokenの重複以外のエラーが返ってきた場合
NSLog(@"%@", error);
}
} else {
//端末情報の登録が成功した場合の処理
NSLog(@"Success");
}
}];
}
// deviceTokenの重複で端末情報の登録に失敗した場合に上書き処理を行う
- (void)updateExistInstallation:(NCMBInstallation*)currentInstallation{
NCMBQuery *installationQuery = [NCMBInstallation query];
[installationQuery whereKey:@"deviceToken" equalTo:currentInstallation.deviceToken];
NSError *searchErr = nil;
NCMBInstallation *searchDevice = [installationQuery getFirstObject:&searchErr];
if (searchErr){
//端末情報の検索に失敗した場合の処理
NSLog(@"%@", searchErr);
} else {
//上書き保存する
currentInstallation.objectId = searchDevice.objectId;
[currentInstallation saveInBackgroundWithBlock:^(NSError *error) {
if (error){
//端末情報更新に失敗したときの処理
NSLog(@"%@", error);
} else {
//端末情報更新に成功したときの処理
NSLog(@"Rewrite Success");
}
}];
}
}
[installation setDeviceTokenFromData:deviceToken];여기는 이것을하는 것만으로 좋은 것은 상당히 기쁩니다!mBaaS 라이브러리 소스를 보면 < , > , が弾かれるようになっていました。
とりあえずここまででiOSアプリ側のプッシュ通知を受け取るための準備は完了!
mBaaS 측 작업
前提としてすでに上記サイトで AppID


작성한 AppID 의 것을 선택한다.

위의 이미지와 같은 것이 나오므로 Edit

아직 Certificate를 만들지 않은 경우 KeyChain에서 인증서를 요청합니다.
Certificate 작성


ユーザのメールアドレス 는 Apple Developer에 등록한 이메일 주소입니다. 통칭은 뭐든지 좋은 것일까? (잘못되면 알려주세요!)
적당한 장소에 작성·저장하면 Create Certificate 를 클릭해 지시에 따라 *.cer 파일을 다운로드한다
p12 파일 작성
다운로드한 aps_development.cer 또는 aps.cer를 가져와 KeyChain에 등록

이러한 느낌에 추가되므로 경우에 따라 p12 파일을 보조 클릭에서 내보내십시오.
서버에 적용
니프티 클라우드mobile backend
상기에 로그인을 한다.


대체로 이런 느낌에 절차를 진행한다.
그리고는 プッシュ通知 탭을 선택해 그 근처에 있는 새롭게 푸시 통지를 작성할 수 있을 것 같은 이하와 같은 이미지를 누르.

iOS 앱은 이미 푸시 알림 수락 알림을 표시하고 OK가 선택되어있는 상태라면 그대로 푸시 알림을 만듭니다!
그리고는 기다린다! !
이제 푸시 알림이 오면 우선 성공! !
푸시 알림 열기를 mBaaS에 알립니다.
AppDelegate.m- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[NCMBAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
// 処理
}
푸시 알림은 이전에 기사를 작성했으므로 아래 링크를 참조하십시오.
앱이 실행되고 있지 않은 경우의 Push 통지로부터의 기동 동작에 대해서
결론
얼마간 간단한 구현을 해 보았습니다만, 어떠셨습니까?
이전에 파이썬에서 푸시 알림을 구현하는 기사 을 썼습니다만, 이쪽도 맞추어 어떠한 테스트를 할 수 있으면 조금 좋을지도요!
Reference
이 문제에 관하여(nifty cloud mobile backend에서 Push 알림 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/nnsnodnb/items/0ddde46920f06d3cda91텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)