Application is Blank after adding AppDelegate
Application is Blank after adding AppDelegate
I have a iOS Application in Cordova with Push Notification implemented using OneSignal.
I have followed all the steps in the documentation given here
The problem is that, when I install the app using XCode the application asks,
AppName Would like to send you notification
But after that everything goes black screen.
I assume that it is because of the AppDelegate.m file which is the following
/*
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
I have replaced the ID as well. And in XCode logs it display few warning, which are
2018-06-29 12:33:16.661 ReachApp[721:311194] DiskCookieStorage
changing policy from 2 to 0, cookie file:
file:///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] Called init with app ID:
(null) 2018-06-29 12:33:16.934 ReachApp[721:311194] Called init with
app ID: Displays_Actual_App_ID_here 2018-06-29 12:33:17.019
ReachApp[721:311194] WARNING: OneSignal has detected that your
application delegate implements a deprecated method
(application:didReceiveLocalNotification:). Please note that this
method has been officially deprecated and the OneSignal SDK will no
longer call it. You should use UNUserNotificationCenter instead
2018-06-29 12:33:17.020 ReachApp[721:311194] WARNING: OneSignal has
detected that your application delegate implements a deprecated method
(application:handleActionWithIdentifier:forLocalNotification:completionHandler:).
Please note that this method has been officially deprecated and the
OneSignal SDK will no longer call it. You should use
UNUserNotificationCenter instead 2018-06-29 12:33:17.020
ReachApp[721:311194] WARNING: OneSignal has detected that your
application delegate implements a deprecated method
(application:didReceiveLocalNotification:). Please note that this
method has been officially deprecated and the OneSignal SDK will no
longer call it. You should use UNUserNotificationCenter instead
2018-06-29 12:33:17.028 ReachApp[721:311194] WARNING: OneSignal has
detected that your application delegate implements a deprecated method
(application:handleActionWithIdentifier:forLocalNotification:completionHandler:).
Please note that this method has been officially deprecated and the
OneSignal SDK will no longer call it. You should use
UNUserNotificationCenter instead
2 Answers
2
I think there are two separate issues. The reason for the blank screen problem probably is that the app doesn't know which View Controller to display. If you are using a storyboard you can set the desired View Controller as 'Initial View Controller'.
Or you can add
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
to the end of:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
just above return YES;
return YES;
Please add below methods to handle notification in your 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
{
}
ok..i update a code
– Rakesh Patel
Jun 29 at 7:25
check updated code
– Rakesh Patel
Jun 29 at 7:28
I have added the code in AppDelegate, still no difference the screen goes black.
– Usama Rehan
Jun 29 at 7:32
What about xcode warning? Still appear?
– Rakesh Patel
Jun 29 at 7:40
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you please give the relevant code for Objective - C.
– Usama Rehan
Jun 29 at 7:23