ios推送通知终止应用程序

发布于 2024-11-28 20:47:11 字数 5045 浏览 2 评论 0 原文

我想在单击推送通知上的查看按钮时启动我的应用程序,但如果应用程序不在后台,我的应用程序就会终止。

这是我来自控制台的错误消息。

Aug  9 10:35:41 unknown listingApp[4527] <Error>: -[__NSCFDictionary absoluteString]: unrecognized selector sent to instance 0x1a8b50
Aug  9 10:35:41 unknown listingApp[4527] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary absoluteString]: unrecognized selector sent to instance 0x1a8b50'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x36df764f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x34050c5d objc_exception_throw + 24
    2   CoreFoundation                      0x36dfb1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x36dfa649 ___forwarding___ + 508
    4   CoreFoundation                      0x36d71180 _CF_forwarding_prep_0 + 48
    5   listingApp                          0x00002d09 -[AppDelegate application:didFinishLaunchingWithOptions:] + 220
    6   UIKit                               0x35c12821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
    7   UIKit                               0x35c0cb65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
    8   UIKit                               0x35be17d7 -[UIApplication handleEvent:withNewEvent:] + 1114
    9   UIKit                               0x35be1215 -[UIApplication sendEvent:] + 44
    10  UIKit                               0x35be0c53 _UIApplicationHandleEvent + 5090
    11  GraphicsServices                    0x3651be77 PurpleEventCallback + 666
    12  CoreFoundation                      0x36dcea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    13  CoreFoundation                      0x36dd083f __CFRunLoopDoSource1 + 166
    14  CoreFoundation                      0x36dd160d __CFRunLoopRun + 520
    15  CoreFoundation                      0x36d61ec3 CFRunLoopRunSpecific + 230
    16  CoreFoundation                      0x36d61dcb CFRunLoopRunInMode + 58
    17  UIKit                               0x35c0bd49 -[UIApplication _run] + 372
    18  UIKit                               0x35c09807 UIApplicationMain + 670
    19  listingApp                          0x00002b93 main + 78
    20  listingApp                          0x00002b0c start + 52
)
Aug  9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: terminate called after throwing an instance of '
Aug  9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: NSException
Aug  9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: '
Aug  9 10:35:41 unknown ReportCrash[4528] <Notice>: Formulating crash report for process listingApp[4527]
Aug  9 10:35:41 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:co.isale.isale[0xc768]) Job appears to have crashed: Abort trap: 6

这是我的 didFinishlaunchWithOptions 的开始,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   

NSLog(@"didFinishLaunchingWithOptions");
viewController.webView = webView;
[viewController.view addSubview:webView];


// read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
NSArray* supportedOrientations = [self parseInterfaceOrientations:
                                           [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]];

// read from PhoneGap.plist in the app bundle
NSDictionary *temp = [[self class] getBundlePlist:@"PhoneGap"];
settings = [[NSDictionary alloc] initWithDictionary:temp];

viewController = [ [ PhoneGapViewController alloc ] init ];

NSNumber *useLocation          = [settings objectForKey:@"UseLocation"];
NSString *topActivityIndicator = [settings objectForKey:@"TopActivityIndicator"];


// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
[[UIApplication sharedApplication] setStatusBarOrientation:[[supportedOrientations objectAtIndex:0] intValue]];

// push notification 
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// end of push notification

这段代码来自另一个名为 AppDelegate.m 的委托文件,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


NSArray *keyArray = [launchOptions allKeys];
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) 
{
    NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
    self.invokeString = [url absoluteString];
    NSLog(@"listingApp launchOptions = %@",url);
}

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

请帮忙? 非常感谢谢谢:)

I want to launch my app when clicking view button on push notification but my app gets terminated if the app is not in background.

here is my error message from console.

Aug  9 10:35:41 unknown listingApp[4527] <Error>: -[__NSCFDictionary absoluteString]: unrecognized selector sent to instance 0x1a8b50
Aug  9 10:35:41 unknown listingApp[4527] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary absoluteString]: unrecognized selector sent to instance 0x1a8b50'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x36df764f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x34050c5d objc_exception_throw + 24
    2   CoreFoundation                      0x36dfb1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x36dfa649 ___forwarding___ + 508
    4   CoreFoundation                      0x36d71180 _CF_forwarding_prep_0 + 48
    5   listingApp                          0x00002d09 -[AppDelegate application:didFinishLaunchingWithOptions:] + 220
    6   UIKit                               0x35c12821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
    7   UIKit                               0x35c0cb65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
    8   UIKit                               0x35be17d7 -[UIApplication handleEvent:withNewEvent:] + 1114
    9   UIKit                               0x35be1215 -[UIApplication sendEvent:] + 44
    10  UIKit                               0x35be0c53 _UIApplicationHandleEvent + 5090
    11  GraphicsServices                    0x3651be77 PurpleEventCallback + 666
    12  CoreFoundation                      0x36dcea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    13  CoreFoundation                      0x36dd083f __CFRunLoopDoSource1 + 166
    14  CoreFoundation                      0x36dd160d __CFRunLoopRun + 520
    15  CoreFoundation                      0x36d61ec3 CFRunLoopRunSpecific + 230
    16  CoreFoundation                      0x36d61dcb CFRunLoopRunInMode + 58
    17  UIKit                               0x35c0bd49 -[UIApplication _run] + 372
    18  UIKit                               0x35c09807 UIApplicationMain + 670
    19  listingApp                          0x00002b93 main + 78
    20  listingApp                          0x00002b0c start + 52
)
Aug  9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: terminate called after throwing an instance of '
Aug  9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: NSException
Aug  9 10:35:41 unknown UIKitApplication:co.isale.isale[0xc768][4527] <Notice>: '
Aug  9 10:35:41 unknown ReportCrash[4528] <Notice>: Formulating crash report for process listingApp[4527]
Aug  9 10:35:41 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:co.isale.isale[0xc768]) Job appears to have crashed: Abort trap: 6

and this is the beginning of my didFinishlaunchWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   

NSLog(@"didFinishLaunchingWithOptions");
viewController.webView = webView;
[viewController.view addSubview:webView];


// read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
NSArray* supportedOrientations = [self parseInterfaceOrientations:
                                           [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]];

// read from PhoneGap.plist in the app bundle
NSDictionary *temp = [[self class] getBundlePlist:@"PhoneGap"];
settings = [[NSDictionary alloc] initWithDictionary:temp];

viewController = [ [ PhoneGapViewController alloc ] init ];

NSNumber *useLocation          = [settings objectForKey:@"UseLocation"];
NSString *topActivityIndicator = [settings objectForKey:@"TopActivityIndicator"];


// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
[[UIApplication sharedApplication] setStatusBarOrientation:[[supportedOrientations objectAtIndex:0] intValue]];

// push notification 
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// end of push notification

this code is from another delegate file called AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


NSArray *keyArray = [launchOptions allKeys];
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) 
{
    NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
    self.invokeString = [url absoluteString];
    NSLog(@"listingApp launchOptions = %@",url);
}

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

please help?
many thanks thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光瘦了 2024-12-05 20:47:11

您似乎在字典上调用 absoluteString ,您可能打算在 NSURL 对象上执行此操作。

重新查看您最新的代码示例:

您正在做一些非常奇怪的事情,试图在 launchOptions 字典中找到第一个键。这不是如何使用词典。您应该使用密钥(列出此处),如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]

    if (url)
    {
        self.invokeString = [url absoluteString];
        NSLog(@"listingApp launchOptions = %@", url);
    }

    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

You seem to be calling absoluteString on a dictionary, where you probably meant to do it on an NSURL object.

Re your latest code sample:

You are doing something very strange, trying to find the first key in the launchOptions dictionary. This is not how to use dictionaries. You should use the keys (listed here under Launch Options Keys) directly, like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]

    if (url)
    {
        self.invokeString = [url absoluteString];
        NSLog(@"listingApp launchOptions = %@", url);
    }

    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
﹎☆浅夏丿初晴 2024-12-05 20:47:11

看起来您还没有实现方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

收到通知时会调用此方法。

It looks like you haven't implemented the method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

This method is called when a notification is received.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文