我在Cordova中有一个iOS应用程序,其中使用OneSignal实现了推送通知。
我已按照here
中提供的文档中的所有步骤进行操作问题是,当我使用XCode安装应用程序时,应用程序会询问,
AppName想向您发送通知
但是此后一切都变成黑屏。
我认为是由于以下的AppDelegate.m文件
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
//
// AppDelegate.m
// ReachApp
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#import "AppDelegate.h"
#import "MainViewController.h"
#import <OneSignal/OneSignal.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Replace '11111111-2222-3333-4444-0123456789ab' with your OneSignal App ID.
[OneSignal initWithLaunchOptions:launchOptions
appId:@"11111111-2222-3333-4444-0123456789ab"
handleNotificationAction:nil
settings:@{kOSSettingsKeyAutoPrompt: @false}];
OneSignal.inFocusDisplayType = OSNotificationDisplayTypeNotification;
// Recommend moving the below line to prompt for push after informing the user about
// how your app will use them.
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
NSLog(@"User accepted notifications: %d", accepted);
}];
return YES;
}
@end
我也替换了ID。在XCode日志中,它显示的警告很少,
2018-06-29 12:33:16.661 ReachApp [721:311194] DiskCookieStorage 将策略从2更改为0,Cookie文件: 文件:///private/var/mobile/Containers/Data/Application/4C0D3ECB-1F40-4668-BE78-AE1EF3CB7810/Library/Cookies/Cookies.binarycookies 2018-06-29 12:33:16.838 ReachApp [721:311194]通过应用ID调用了init: (空)2018-06-29 12:33:16.934 ReachApp [721:311194]称为init 应用ID:Displays_Actual_App_ID_here 2018-06-29 12:33:17.019 ReachApp [721:311194]警告:OneSignal已检测到您的 应用程序委托实现不推荐使用的方法 (应用程序:didReceiveLocalNotification :)。请注意 方法已正式弃用,并且OneSignal SDK将不会 再说吧。您应该改用UNUserNotificationCenter 2018-06-29 12:33:17.020 ReachApp [721:311194]警告:OneSignal具有 检测到您的应用程序委托实现了不推荐使用的方法 (应用程序:handleActionWithIdentifier:forLocalNotification:completionHandler :)。 请注意,此方法已被正式弃用, OneSignal SDK将不再调用它。你应该用 而是改为使用UNUserNotificationCenter 2018-06-29 12:33:17.020 ReachApp [721:311194]警告:OneSignal已检测到您的 应用程序委托实现不推荐使用的方法 (应用程序:didReceiveLocalNotification :)。请注意 方法已正式弃用,并且OneSignal SDK将不会 再说吧。您应该改用UNUserNotificationCenter 2018-06-29 12:33:17.028 ReachApp [721:311194]警告:OneSignal具有 检测到您的应用程序委托实现了不推荐使用的方法 (应用程序:handleActionWithIdentifier:forLocalNotification:completionHandler :)。 请注意,此方法已被正式弃用, OneSignal SDK将不再调用它。你应该用 而是改为使用UNUserNotificationCenter
答案 0 :(得分:1)
我认为有两个独立的问题。黑屏问题的原因可能是该应用程序不知道要显示哪个View Controller。如果您使用的是故事板,则可以将所需的View Controller设置为“ Initial View Controller”。
或者您可以添加
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
到结尾:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
正好位于return YES;
答案 1 :(得分:0)
请添加以下方法来处理您的appdelegate中的通知。
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"Application registered for notification");
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Failed to register notification for application");
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
}