菜鸟教程小白 发表于 2022-12-12 16:05:31

iOS 8 通知操作按钮未显示


                                            <p><p>我正在尝试使用操作按钮发送本地通知。
通知没问题。但是不显示操作按钮。
我正在使用 Xcode 6.3.2 iPhone 6 iOS 8.2</p>

<hr/>

<p>发送通知</p>

<pre><code>UIApplication *myapp = ;
UILocalNotification *test = [ init];

if(test) {
    NSLog(@&#34;Sending notification&#34;);

    test.alertBody = @&#34;jothi test alert&#34;;
    test.alertTitle = @&#34;kottapa&#34;;

    test.soundName = UILocalNotificationDefaultSoundName;
    test.alertAction = NSLocalizedString(@&#34;View Details&#34;, nil);
    test.category = @&#34;MY_CATEGORY&#34;;

    ;
}
</code></pre>

<hr/>

<p>在应用委托(delegate)中<code>didFinishLaunchingWithOptions:</code></p>

<pre><code>UIMutableUserNotificationAction *myAction =
[ init];

myAction.identifier = @&#34;MY_IDENTIFIER&#34;;      
myAction.title = @&#34;Test Action&#34;;
myAction.activationMode = UIUserNotificationActivationModeBackground;
myAction.destructive = NO;
myAction.authenticationRequired = NO;

//------------

// First create the category
UIMutableUserNotificationCategory *inviteCategory =
   [ init];

// Identifier to include in your push payload and local notification
inviteCategory.identifier = @&#34;MY_CATEGORY&#34;;

// Add the actions to the category and set the action context

                forContext:UIUserNotificationActionContextDefault];

// Set the actions to present in a minimal context

                forContext:UIUserNotificationActionContextMinimal];

NSSet *categories = ;

UIUserNotificationSettings *settings =
    [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound
                                    categories:categories];

[ registerUserNotificationSettings:settings];
</code></pre>

<p> <a href="/image/weCCG.jpg" rel="noreferrer noopener nofollow"><img src="/image/weCCG.jpg" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您的代码有效,您只需向左滑动通知即可看到操作按钮(或将其拉下,如果它从顶部以横幅形式呈现,则设备未锁定)。</p>

<p>另外,我猜你已经这样做了,只是没有包含代码,为了处理用户选择的操作,你需要在你的应用委托(delegate)中实现这个方法:</p>

<pre><code>- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler
</code></pre>

<p> <a href="/image/NDMAH.png" rel="noreferrer noopener nofollow"><img src="/image/NDMAH.png" alt="enter image description here"/></a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS 8 通知操作按钮未显示,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32109729/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32109729/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS 8 通知操作按钮未显示