English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
iOS10XCode에 대한 다양한 조정이 인터넷에서 발표된 후에 공식 출시됩니다8및 iOS10에 대한 기사가 많이 퍼져 있습니다.10원격 푸시에 대한 기사는 많지 않습니다. iOS10푸시 수정은 매우 큰 변화를 가져왔습니다. UserNotifications 프레임워크가 추가되었으며, 오늘은 자신의 프로젝트와 함께 실제 적응 사례를 설명하겠습니다.
능력(Capabilities)에서 푸시 알림 스위치를 켭니다
에서7에서 여기의 스위치가 꺼져도 푸시는 정상적으로 사용될 수 있습니다. 하지만 XCode8에서, 여기의 스위치는 반드시 켜져야 합니다. 아니면 오류가 발생합니다:
Error Domain=NSCocoaErrorDomain Code=3000 "애플리케이션의 "aps-environment”의 인증 문자열" UserInfo={NSLocalizedDescription=애플리케이션의 "aps-environment”의 인증 문자열}
열리면 entitlements 파일이 생성되며, 여기서 APS 환경
2. 푸시 등록
먼저 UserNotifications 프레임워크를 포함합니다.
import <UserNotifications/UserNotifications.h>
iOS10푸시 등록 방법을 수정했습니다. 여기서는 다른 버전에 대해 각각 설정해야 합니다. application didFinishLaunchingWithOptions 메서드에서 이전 푸시 설정을 수정했습니다(저는 iOS8이 설정 이상)
if (IOS_VERSION >= 10.0) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) { if (!error) { DLog(@"요청 인증이 성공했습니다!"); } }] } else { if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { //IOS8를 생성하고 메시지 표시 유형을 설정합니다 UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil]; [application registerUserNotificationSettings:notiSettings]; } }
3. UNUserNotificationCenterDelegate 대리자 구현
iOS10UNUserNotificationCenterDelegate의 두 메서드를 구현하여 푸시 메시지를 처리하는 것이 필요합니다:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
이전에는 푸시 알림을 처리할 때 userInfo 매개변수 안에 정보가 있었지만, 새로운 메서드에서는 보이는 것처럼 그런 매개변수가 없지만 실제로는 userInfo를 얻을 수 있습니다. 예를 들어:
/// App이 전면 상태일 때 호출됩니다 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { NSDictionary *userInfo = notification.request.content.userInfo; [self handleRemoteNotificationForcegroundWithUserInfo:userInfo]; } /// App이 백그라운드에서 푸시를 클릭할 때 호출됩니다 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { NSDictionary *userInfo = response.notification.request.content.userInfo; [self handleRemoteNotificationBackgroundWithUserInfo:userInfo]; }
위 세 가지 단계의 설정을 완료한 후, iOS에 대해10의 푸시 설정은 기본적으로 적응되었습니다. Notification Content를自定义하거나 다른 NotificationAction를 구현하려면 다른 문서를 참조하십시오. 여기서는 iOS에 대한 적응만 했습니다.10의 적응.
이 문서는 《iOS 푸시 강의》에 정리되었습니다. 많은 학습과 독서를 바랍니다.
이것이 이 문서의 모든 내용입니다. 많은 도움이 되길 바라며, 많이 지지해 주셔서 감사합니다. 다른 강의를 많이 지지해 주세요.
선언: 이 문서의 내용은 인터넷에서 가져왔으며, 저작권은 원작자에게 있으며, 인터넷 사용자가 자발적으로 기여하고 업로드한 내용입니다. 이 사이트는 소유권을 가지지 않으며, 인공적인 편집을 하지 않았으며, 관련 법적 책임을 부담하지 않습니다. 저작권 침해가 의심되는 내용이 있다면, 이메일을 notice#w로 보내 주시기 바랍니다.3codebox.com(보내는 이메일에서 #을 @으로 변경하시오. 신고를 하시고 관련 증거를 제공하시면, 사실이 확인되면, 이 사이트는 즉시 의심스러운 저작권 내용을 삭제합니다。)